123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- package com.yyrh.pay;
- import android.os.Handler;
- import android.os.Message;
- import com.yyrh.networking.urlhttp.CallBackUtil;
- import com.yyrh.networking.urlhttp.UrlHttpUtil;
- import com.yyrh.sdk.SDKEntry;
- import com.yyrh.utils.YYLog;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.Date;
- import java.util.HashMap;
- public class PaymentNotify extends Handler {
- private static final int MAX_TIME = 5;
- @Override
- public void handleMessage(final Message msg) {
- super.handleMessage(msg);
- final HashMap<String, String> payInfo = (HashMap<String, String>) msg.obj;
- String url = payInfo.get("url");
- // url = "http://testmixplatformapi.yyxxgame.com:9003/client_test";
- int times = 0;
- if (payInfo.containsKey("resend_times")) {
- times = Integer.valueOf(payInfo.get("resend_times")).intValue();
- payInfo.remove("resend_times");
- }
- final int finalTimes = times;
- UrlHttpUtil.post(url, new CallBackUtil.CallBackString() {
- @Override
- public void onFailure(int code, String errorMessage) {
- if (finalTimes < MAX_TIME) {
- payInfo.put("resend_times", finalTimes + 1 + "");
- Message msg = new Message();
- msg.what = 1;
- msg.obj = payInfo;
- YYLog.i( "PaymentNotify-payInfo: NetWork Error" + payInfo.toString());
- switch (finalTimes) {
- case 0:
- sendMessageDelayed(msg, 10000);
- break;
- case 1:
- sendMessageDelayed(msg, 30000);
- break;
- case 2:
- sendMessageDelayed(msg, 60000);
- break;
- case 3:
- sendMessageDelayed(msg, 180000);
- break;
- case 4:
- sendMessageDelayed(msg, 300000);
- break;
- }
- }
- }
- @Override
- public void onResponse(String response) {
- JSONObject json = null;
- try {
- json = new JSONObject(response);
- } catch (JSONException e) {
- e.printStackTrace();
- }
- int code = json.optInt("code",-1);
- if (code != 1 && finalTimes < MAX_TIME){
- payInfo.put("resend_times", finalTimes + 1 + "");
- Message msg = new Message();
- msg.what = 1;
- msg.obj = payInfo;
- YYLog.i( "PaymentNotify-payInfo:" + payInfo.toString());
- switch (finalTimes){
- case 0:
- sendMessageDelayed(msg, 10000);
- break;
- case 1:
- sendMessageDelayed(msg, 30000);
- break;
- case 2:
- sendMessageDelayed(msg, 60000);
- break;
- case 3:
- sendMessageDelayed(msg, 180000);
- break;
- case 4:
- sendMessageDelayed(msg, 300000);
- break;
- }
- }else{
- SDKEntry.getSdkInstance().sdkCallback.onPayFinishCallback(true,"pay success");
- }
- }
- });
- }
- }
|