use of cn.beecloud.entity.BCQueryReqParams in project ttdj by soonphe.
the class BCWXWapPaymentActivity method onResume.
public void onResume() {
super.onResume();
synchronized (this) {
if (firstIn) {
firstIn = false;
return;
}
}
final ProgressDialog loadingDialog = new ProgressDialog(this);
loadingDialog.setMessage("处理中,请稍候...");
loadingDialog.setIndeterminate(true);
loadingDialog.setCancelable(false);
loadingDialog.show();
BCCache.executorService.execute(new Runnable() {
@Override
public void run() {
boolean found = false;
// 总共查3次
for (int i = 0; i < 3; i++) {
BCQueryReqParams bcQueryReqParams;
try {
bcQueryReqParams = new BCQueryReqParams(BCReqParams.BCChannelTypes.ALL);
} catch (BCException e) {
Log.w(TAG, e.getMessage() + "");
return;
}
String queryURL = BCHttpClientUtil.getBillQueryURL() + "/" + BCCache.getInstance().billID + "?para=";
BCHttpClientUtil.Response response = BCHttpClientUtil.httpGet(queryURL + bcQueryReqParams.transToEncodedJsonString());
if (response.code == 200 || (response.code >= 400 && response.code < 500)) {
try {
BCQueryBillResult billResult = BCQueryBillResult.transJsonToResultObject(response.content);
// 如果查询到成功退出
if (billResult.getResultCode() == 0 && billResult.getBill().getPayResult() != null && billResult.getBill().getPayResult()) {
if (BCPay.payCallback != null) {
BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_SUCCESS, BCPayResult.APP_PAY_SUCC_CODE, BCPayResult.RESULT_SUCCESS, "用户支付成功", BCCache.getInstance().billID));
}
found = true;
break;
}
} catch (JsonSyntaxException ex) {
Log.w(TAG, ex.getMessage() + "");
}
}
try {
// 0.5s后继续查
Thread.sleep(500);
} catch (InterruptedException e) {
Log.w(TAG, e.getMessage() + "");
}
}
if (!found) {
// 如果一直没有查询到支付结果
if (BCPay.payCallback != null) {
BCPay.payCallback.done(new BCPayResult(BCPayResult.RESULT_CANCEL, BCPayResult.APP_PAY_CANCEL_CODE, BCPayResult.RESULT_CANCEL, "用户未支付,或服务器通信延迟,如果用户确认已支付,请注意webhook推送", BCCache.getInstance().billID));
}
}
loadingDialog.dismiss();
finish();
}
});
}
Aggregations