public void onClick(DialogInterface dialoginterface, int i) {
//
((Activity)context).finish();
}
}).show();
return;
}
api = WXAPIFactory.createWXAPI(context, null);
req = new PayReq();
//生成prepay_id
GetPrepayIdTask getPrepayId = new GetPrepayIdTask();
getPrepayId.execute();
}
/**
-
用于获取
-
@author 95
*/
private class GetPrepayIdTask extends AsyncTask<void, string=“”>> {
private ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(context, “提示”, “正在获取预支付订单…”);
}
@Override
protected void onPostExecute(Map<string,string> result) {
if (dialog != null) {
dialog.dismiss();
}
resultunifiedorder=result;
genPayReq();
}
@Override
protected void onCancelled() {
super.onCancelled();
}
@Override
protected Map<string,string> doInBackground(Void… params) {
String url = String.format(“https://api.mch.weixin.qq.com/pay/unifiedorder”);
String entity = genProductArgs();
Log.e(“orion”,entity);
byte[] buf = httpPost(url, entity);
String content = new String(buf);
Log.e(“orion”, content);
Map<string,string> xml=decodeXml(content);
return xml;
}
}
private void genPayReq() {
req.appId = ParameterConfig.WX_APP_ID;
req.partnerId = ParameterConfig.WX_MCH_ID;
req.prepayId = resultunifiedorder.get(“prepay_id”);
req.packageValue = “prepay_id=”+resultunifiedorder.get(“prepay_id”);
req.nonceStr = genNonceStr();
req.timeStamp = String.valueOf(genTimeStamp());
List signParams = new LinkedList();
signParams.add(new BasicNameValuePair(“appid”, req.appId));
signParams.add(new BasicNameValuePair(“noncestr”, req.nonceStr));
signParams.add(new BasicNameValuePair(“package”, req.packageValue));
signParams.add(new BasicNameValuePair(“partnerid”, req.partnerId));
signParams.add(new BasicNameValuePair(“prepayid”, req.prepayId));
signParams.add(new BasicNameValuePair(“timestamp”, req.timeStamp));
req.sign = genAppSign(signParams);
Log.e(“orion”, signParams.toString());
sendPayReq();
}
private void sendPayReq() {
api.registerApp(ParameterConfig.WX_APP_ID);
api.sendReq(req);
}
private String genProductArgs() {
StringBuffer xml = new StringBuffer();
try {
String nonceStr = genNonceStr();
xml.append(“”);
List packageParams = ne