微信支付寶支付訂單撤銷交易查詢案例
阿新 • • 發佈:2019-01-22
/**
* 支付寶撤銷交易
* 已經成功
* @param
* @return
*/ private void outAliapyTradeCancel() {
Debug.v("outAliapyTradeCance ", "支付寶撤銷"); new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub AlipayClient alipayClient = new DefaultAlipayClient(AlipayUtils.openapi, AlipayUtils.appid,
AlipayUtils.private_key, "json", "GBK", AlipayUtils.public_key, "RSA2");
AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); request.putOtherTextParam("app_auth_token", "###################");
request.setBizContent("{" + // "\"out_trade_no\":\"" + outTradeNo + "\"," +
"\"trade_no\":\"" + tradeNo + "\"" + " }"); AlipayTradeCancelResponse response;
try {
response = alipayClient.execute(request);
Debug.v("getMsg", response.getMsg());
Debug.v("code", response.getCode()); if (response.isSuccess()) {
Debug.v("撤銷成功"); Looper.prepare(); ToastUtil.toast("支付寶撤銷成功", Toast.LENGTH_LONG); preferences = getSharedPreferences("TransferMsgActivity", Context.MODE_PRIVATE);
if (preferences.getInt("transFerMsg_cancel", 1) == 1) { Debug.v("preferences", preferences.getInt("transFerMsg_cancel", 1) + "");
preferences = getSharedPreferences("AliapyStatusActivity", Context.MODE_PRIVATE); new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub
info = alipayTradeQuery(tradeNo);
Debug.v("INFO===", info);
if ("SUCCESS".equals(info)) {
Debug.v("INFO===", info);
final Bundle mBundle = new Bundle(); Debug.v("alipayTradeQuery tradeNo", tradeNo);
mBundle.putString("OrderID", alipayOutTradeNo);
mBundle.putString("PayType", "Z");
mBundle.putString("CardID", null);
Debug.v("price ==", preferences.getString("totalAmount", ""));
mBundle.putString("Price", alipayTotalAmount);
Debug.v("alipay MachineID", TransParams.getMachineID());
mBundle.putString("MachineID", TransParams.getMachineID());
mBundle.putString("PayTime", TransParams.getDate());
mBundle.putString("UserName", null);
mBundle.putString("VerifyCode",
TransParams.getVerifyCode(alipayOutTradeNo, TransParams.getDate()));
mBundle.putString("IsBack", "Y"); Map<String, Object> params = TransParams.transFerParams(mBundle);
String result = HttpUtilsGet.doGet(apiurl, params);
Debug.v("支付寶撤銷資訊回傳");
Debug.v("result==", result); }
}
}).start(); } else { Debug.v("preferences AliapyTradeCancel ", "is not 1"); }
Looper.loop();
} else {
Debug.v("撤銷失敗"); Looper.prepare(); ToastUtil.toast("支付寶撤銷失敗", Toast.LENGTH_LONG);
Looper.loop(); } } catch (AlipayApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}).start(); }
* 支付寶撤銷交易
* 已經成功
* @param
* @return
*/ private void outAliapyTradeCancel() {
Debug.v("outAliapyTradeCance ", "支付寶撤銷"); new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub AlipayClient alipayClient = new DefaultAlipayClient(AlipayUtils.openapi, AlipayUtils.appid,
AlipayUtils.private_key, "json", "GBK", AlipayUtils.public_key, "RSA2");
AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); request.putOtherTextParam("app_auth_token", "###################");
request.setBizContent("{" + // "\"out_trade_no\":\"" + outTradeNo + "\"," +
"\"trade_no\":\"" + tradeNo + "\"" + " }"); AlipayTradeCancelResponse response;
try {
response = alipayClient.execute(request);
Debug.v("getMsg", response.getMsg());
Debug.v("code", response.getCode()); if (response.isSuccess()) {
Debug.v("撤銷成功"); Looper.prepare(); ToastUtil.toast("支付寶撤銷成功", Toast.LENGTH_LONG); preferences = getSharedPreferences("TransferMsgActivity", Context.MODE_PRIVATE);
if (preferences.getInt("transFerMsg_cancel", 1) == 1) { Debug.v("preferences", preferences.getInt("transFerMsg_cancel", 1) + "");
preferences = getSharedPreferences("AliapyStatusActivity", Context.MODE_PRIVATE); new Thread(new Runnable() { @Override
public void run() {
// TODO Auto-generated method stub
info = alipayTradeQuery(tradeNo);
Debug.v("INFO===", info);
if ("SUCCESS".equals(info)) {
Debug.v("INFO===", info);
final Bundle mBundle = new Bundle(); Debug.v("alipayTradeQuery tradeNo", tradeNo);
mBundle.putString("OrderID", alipayOutTradeNo);
mBundle.putString("PayType", "Z");
mBundle.putString("CardID", null);
Debug.v("price ==", preferences.getString("totalAmount", ""));
mBundle.putString("Price", alipayTotalAmount);
Debug.v("alipay MachineID", TransParams.getMachineID());
mBundle.putString("MachineID", TransParams.getMachineID());
mBundle.putString("PayTime", TransParams.getDate());
mBundle.putString("UserName", null);
mBundle.putString("VerifyCode",
TransParams.getVerifyCode(alipayOutTradeNo, TransParams.getDate()));
mBundle.putString("IsBack", "Y"); Map<String, Object> params = TransParams.transFerParams(mBundle);
String result = HttpUtilsGet.doGet(apiurl, params);
Debug.v("支付寶撤銷資訊回傳");
Debug.v("result==", result); }
}
}).start(); } else { Debug.v("preferences AliapyTradeCancel ", "is not 1"); }
Looper.loop();
} else {
Debug.v("撤銷失敗"); Looper.prepare(); ToastUtil.toast("支付寶撤銷失敗", Toast.LENGTH_LONG);
Looper.loop(); } } catch (AlipayApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }
}).start(); }