PaymentNotify.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package com.yyrh.pay;
  2. import android.os.Handler;
  3. import android.os.Message;
  4. import com.yyrh.networking.urlhttp.CallBackUtil;
  5. import com.yyrh.networking.urlhttp.UrlHttpUtil;
  6. import com.yyrh.sdk.SDKEntry;
  7. import com.yyrh.utils.YYLog;
  8. import org.json.JSONException;
  9. import org.json.JSONObject;
  10. import java.util.Date;
  11. import java.util.HashMap;
  12. public class PaymentNotify extends Handler {
  13. private static final int MAX_TIME = 5;
  14. @Override
  15. public void handleMessage(final Message msg) {
  16. super.handleMessage(msg);
  17. final HashMap<String, String> payInfo = (HashMap<String, String>) msg.obj;
  18. String url = payInfo.get("url");
  19. // url = "http://testmixplatformapi.yyxxgame.com:9003/client_test";
  20. int times = 0;
  21. if (payInfo.containsKey("resend_times")) {
  22. times = Integer.valueOf(payInfo.get("resend_times")).intValue();
  23. payInfo.remove("resend_times");
  24. }
  25. final int finalTimes = times;
  26. UrlHttpUtil.post(url, new CallBackUtil.CallBackString() {
  27. @Override
  28. public void onFailure(int code, String errorMessage) {
  29. if (finalTimes < MAX_TIME) {
  30. payInfo.put("resend_times", finalTimes + 1 + "");
  31. Message msg = new Message();
  32. msg.what = 1;
  33. msg.obj = payInfo;
  34. YYLog.i( "PaymentNotify-payInfo: NetWork Error" + payInfo.toString());
  35. switch (finalTimes) {
  36. case 0:
  37. sendMessageDelayed(msg, 10000);
  38. break;
  39. case 1:
  40. sendMessageDelayed(msg, 30000);
  41. break;
  42. case 2:
  43. sendMessageDelayed(msg, 60000);
  44. break;
  45. case 3:
  46. sendMessageDelayed(msg, 180000);
  47. break;
  48. case 4:
  49. sendMessageDelayed(msg, 300000);
  50. break;
  51. }
  52. }
  53. }
  54. @Override
  55. public void onResponse(String response) {
  56. JSONObject json = null;
  57. try {
  58. json = new JSONObject(response);
  59. } catch (JSONException e) {
  60. e.printStackTrace();
  61. }
  62. int code = json.optInt("code",-1);
  63. if (code != 1 && finalTimes < MAX_TIME){
  64. payInfo.put("resend_times", finalTimes + 1 + "");
  65. Message msg = new Message();
  66. msg.what = 1;
  67. msg.obj = payInfo;
  68. YYLog.i( "PaymentNotify-payInfo:" + payInfo.toString());
  69. switch (finalTimes){
  70. case 0:
  71. sendMessageDelayed(msg, 10000);
  72. break;
  73. case 1:
  74. sendMessageDelayed(msg, 30000);
  75. break;
  76. case 2:
  77. sendMessageDelayed(msg, 60000);
  78. break;
  79. case 3:
  80. sendMessageDelayed(msg, 180000);
  81. break;
  82. case 4:
  83. sendMessageDelayed(msg, 300000);
  84. break;
  85. }
  86. }else{
  87. SDKEntry.getSdkInstance().sdkCallback.onPayFinishCallback(true,"pay success");
  88. }
  89. }
  90. });
  91. }
  92. }