자바 통합 위 챗 결제 (전체 절차)
1. 위 챗 결제 신청 능력
* , app 、 、h5 。
* 、 , 。
* , appId, 32 。
2. 준비 작업
* h5 , URL IP , 5 IP , IP 。
* , , IP , , URL IP 。
3. 집적 시작
*** APP **
:
1: APP , , 。(app )
2: , 。( )
3: prepay_id, , APP。 appid,partnerid,prepayid,noncestr,timestamp,package。 :package Sign=WXPay( prepayid app )
4: APP 。(app )
5: 。( )
6: 。( app )
:
DecimalFormat df = new DecimalFormat("######0.00");
// id
money=df.format(Double.parseDouble(okamiOrder.getReallMoney()));
//
ReturnValue rv=new ReturnValue();
String token=request.getParameter("token");
// id
String userId=TokenParmValue.getUserId(token);
//
String currTime = TenpayUtil.getCurrTime();
// 8
String strTime = currTime.substring(8, currTime.length());
//
String strRandom = TenpayUtil.buildRandom(4) + "";
// 10 , 。
String strReq =strTime+strRandom;
SONObject retMsgJson = new JSONObject();
//
String appId=""; //appid
String appSecret=""; // appsecret
String partner=""; //
String partnerkey=""; //api
//
appId=WeixinPayUtil.appid;
appSecret=WeixinPayUtil.appsecret;
partner=WeixinPayUtil.partner;
partnerkey=WeixinPayUtil.partnerkey;
//********************************************
//
String sjbh = RandomUtil.getRandomFileName();
//
TreeMap treeMap = new TreeMap();
// appId
treeMap.put("appid",appId);
//
treeMap.put("mch_id",partner);
//
treeMap.put("nonce_str", strReq);
//
treeMap.put("body",subject);
//
treeMap.put("out_trade_no", sjbh);
// ip( ip), IP
treeMap.put("spbill_create_ip", Property.getProperty("weixinIp"));
//
treeMap.put("total_fee",money);
//
treeMap.put("trade_type",WeixinPayUtil.trade_type);
//
treeMap.put("notify_url",Property.getProperty("okamiWeixinUrl").trim());
//
if("3".equals(payType)){
treeMap.put("limit_pay","no_credit");
}
StringBuilder sb = new StringBuilder();
for (String key : treeMap.keySet()) {
sb.append(key).append("=").append(treeMap.get(key)).append("&");
}
sb.append("key="+partnerkey);
//
RequestHandler reqHandler = new RequestHandler(request, response);
reqHandler.init(appId,appSecret,partnerkey);
//
String sign = reqHandler.createSign(treeMap);//
treeMap.put("sign", sign);
StringBuilder xml = new StringBuilder();
xml.append("
");
for (Map.Entry entry : treeMap.entrySet()) {
if ("body".equals(entry.getKey()) || "sign".equals(entry.getKey())) {
xml.append("" + entry.getKey() + ">
");
} else {
xml.append("").append(entry.getValue()).append("" + entry.getKey() + ">
");
}
}
xml.append("");
//
String createOrderURL = WeixinPayUtil.createOrderURL;
String prepay_id = "";
try {
//
prepay_id = GetWxOrderno.getPayNo(createOrderURL,xml.toString());
} catch (Exception e1) {
e1.printStackTrace();
rv.setResult("error");
rv.setMsg(ReturnUtil.PAYMENT_FAILURE);
return new JsonMapper().toJson(rv);
}
log.info(" prepay_id :----------------"+prepay_id);
// prepayid app
SortedMap