PayingActivity.java
public void WxPay(){ // new Thread(new Runnable() { // @Override // public void run() { // // // Button appayBtn = (Button) findViewById(R.id.appay_btn); // //appayBtn.setOnClickListener(new View.OnClickListener() { // // @Override // // public void onClick(View v) { // // final Button payBtn = (Button) findViewById(R.id.appay_btn); // // payBtn.setEnabled(false); // // } // }).start(); Toast.makeText(PayingActivity.this, "獲取訂單中...", Toast.LENGTH_SHORT).show(); HttpUtils httpUtils = new HttpUtils(); httpUtils.send(HttpRequest.HttpMethod.GET, "http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=android", new RequestCallBack<String>() { @Override public void onSuccess(ResponseInfo<String> responseInfo) { String content = responseInfo.result; Log.e("get server pay params:", content); try { JSONObject json = new JSONObject(content); if (null != json && !json.has("retcode")) { PayReq req = new PayReq(); //req.appId = "wxf8b4f85f3a794e77"; // 測試用appId req.appId = json.getString("appid"); req.partnerId = json.getString("partnerid"); req.prepayId = json.getString("prepayid"); req.nonceStr = json.getString("noncestr"); req.timeStamp = json.getString("timestamp"); req.packageValue = json.getString("package"); req.sign = json.getString("sign"); req.extData = "app data"; // optional Toast.makeText(PayingActivity.this, "正常調(diào)起支付", Toast.LENGTH_SHORT).show(); // 在支付之前,如果應(yīng)用沒有注冊(cè)到微信,應(yīng)該先調(diào)用IWXMsg.registerApp將應(yīng)用注冊(cè)到微信 //api.registerApp("wx3c08ef3862b18c98"); api.sendReq(req); } else { Log.d("PAY_GET", "返回錯(cuò)誤" + json.getString("retmsg")); Toast.makeText(PayingActivity.this, "返回錯(cuò)誤" + json.getString("retmsg"), Toast.LENGTH_SHORT).show(); } } catch (Exception e) { e.printStackTrace(); } // payBtn.setEnabled(true); } @Override public void onFailure(HttpException e, String s) { Log.d("PAY_GET", "服務(wù)器請(qǐng)求錯(cuò)誤"); e.printStackTrace(); Toast.makeText(PayingActivity.this, "服務(wù)器請(qǐng)求錯(cuò)誤", Toast.LENGTH_SHORT).show(); // payBtn.setEnabled(true); } }); //} // }); }
?
本文摘自 :https://blog.51cto.com/u