Skip to content

Commit 29cc3f6

Browse files
committed
format
1 parent 214b969 commit 29cc3f6

File tree

2 files changed

+92
-92
lines changed

2 files changed

+92
-92
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,17 @@ public interface WxMpService {
334334
*/
335335
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;
336336

337-
/**
338-
* <pre>
339-
* 换取永久字符串二维码ticket
340-
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
341-
* </pre>
342-
*
343-
* @param scene_str 参数。字符串类型长度现在为1到64
344-
* @return
345-
* @throws WxErrorException
346-
*/
347-
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;
337+
/**
338+
* <pre>
339+
* 换取永久字符串二维码ticket
340+
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
341+
* </pre>
342+
*
343+
* @param scene_str 参数。字符串类型长度现在为1到64
344+
* @return
345+
* @throws WxErrorException
346+
*/
347+
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;
348348

349349
/**
350350
* <pre>

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -338,18 +338,18 @@ public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorExcep
338338
return WxMpQrCodeTicket.fromJson(responseContent);
339339
}
340340

341-
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
342-
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
343-
JsonObject json = new JsonObject();
344-
json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
345-
JsonObject actionInfo = new JsonObject();
346-
JsonObject scene = new JsonObject();
347-
scene.addProperty("scene_str", scene_str);
348-
actionInfo.add("scene", scene);
349-
json.add("action_info", actionInfo);
350-
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
351-
return WxMpQrCodeTicket.fromJson(responseContent);
352-
}
341+
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException {
342+
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create";
343+
JsonObject json = new JsonObject();
344+
json.addProperty("action_name", "QR_LIMIT_STR_SCENE");
345+
JsonObject actionInfo = new JsonObject();
346+
JsonObject scene = new JsonObject();
347+
scene.addProperty("scene_str", scene_str);
348+
actionInfo.add("scene", scene);
349+
json.add("action_info", actionInfo);
350+
String responseContent = execute(new SimplePostRequestExecutor(), url, json.toString());
351+
return WxMpQrCodeTicket.fromJson(responseContent);
352+
}
353353

354354
public File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException {
355355
String url = "https://mp.weixin.qq.com/cgi-bin/showqrcode";
@@ -631,77 +631,77 @@ public void setMaxRetryTimes(int maxRetryTimes) {
631631
this.maxRetryTimes = maxRetryTimes;
632632
}
633633

634-
@Override
635-
public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
636-
String nonce_str = System.currentTimeMillis() + "";
637-
638-
SortedMap<String, String> packageParams = new TreeMap<String, String>();
639-
packageParams.put("appid", wxMpConfigStorage.getAppId());
640-
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
641-
packageParams.put("nonce_str", nonce_str);
642-
packageParams.put("body", body);
643-
packageParams.put("out_trade_no", outTradeNo);
644-
645-
packageParams.put("total_fee", (int)(amt*100) + "");
646-
packageParams.put("spbill_create_ip", ip);
647-
packageParams.put("notify_url", callbackUrl);
648-
packageParams.put("trade_type", tradeType);
649-
packageParams.put("openid", openId);
650-
651-
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
652-
String xml = "<xml>" +
653-
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
654-
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
655-
"<nonce_str>" + nonce_str + "</nonce_str>" +
656-
"<sign>" + sign + "</sign>" +
657-
"<body><![CDATA[" + body + "]]></body>" +
658-
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
659-
"<total_fee>" + packageParams.get("total_fee") + "</total_fee>" +
660-
"<spbill_create_ip>" + ip + "</spbill_create_ip>" +
661-
"<notify_url>" + callbackUrl + "</notify_url>" +
662-
"<trade_type>" + tradeType + "</trade_type>" +
663-
"<openid>" + openId + "</openid>" +
664-
"</xml>";
665-
666-
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/unifiedorder");
667-
if (httpProxy != null) {
668-
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
669-
httpPost.setConfig(config);
670-
}
671-
672-
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
673-
httpPost.setEntity(entity);
674-
try {
675-
CloseableHttpResponse response = httpClient.execute(httpPost);
676-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
677-
XStream xstream = XStreamInitializer.getInstance();
678-
xstream.alias("xml", WxMpPrepayIdResult.class);
679-
WxMpPrepayIdResult wxMpPrepayIdResult = (WxMpPrepayIdResult) xstream.fromXML(responseContent);
680-
return wxMpPrepayIdResult;
681-
} catch (IOException e) {
682-
e.printStackTrace();
683-
}
684-
return new WxMpPrepayIdResult();
634+
@Override
635+
public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
636+
String nonce_str = System.currentTimeMillis() + "";
637+
638+
SortedMap<String, String> packageParams = new TreeMap<String, String>();
639+
packageParams.put("appid", wxMpConfigStorage.getAppId());
640+
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
641+
packageParams.put("nonce_str", nonce_str);
642+
packageParams.put("body", body);
643+
packageParams.put("out_trade_no", outTradeNo);
644+
645+
packageParams.put("total_fee", (int)(amt*100) + "");
646+
packageParams.put("spbill_create_ip", ip);
647+
packageParams.put("notify_url", callbackUrl);
648+
packageParams.put("trade_type", tradeType);
649+
packageParams.put("openid", openId);
650+
651+
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
652+
String xml = "<xml>" +
653+
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
654+
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
655+
"<nonce_str>" + nonce_str + "</nonce_str>" +
656+
"<sign>" + sign + "</sign>" +
657+
"<body><![CDATA[" + body + "]]></body>" +
658+
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
659+
"<total_fee>" + packageParams.get("total_fee") + "</total_fee>" +
660+
"<spbill_create_ip>" + ip + "</spbill_create_ip>" +
661+
"<notify_url>" + callbackUrl + "</notify_url>" +
662+
"<trade_type>" + tradeType + "</trade_type>" +
663+
"<openid>" + openId + "</openid>" +
664+
"</xml>";
665+
666+
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/unifiedorder");
667+
if (httpProxy != null) {
668+
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
669+
httpPost.setConfig(config);
685670
}
686671

687-
@Override
688-
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
689-
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(openId, outTradeNo, amt, body, tradeType, ip, callbackUrl);
690-
String prepayId = wxMpPrepayIdResult.getPrepay_id();
691-
if (prepayId == null || prepayId.equals("")) {
692-
throw new RuntimeException("get prepayid error");
693-
}
672+
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
673+
httpPost.setEntity(entity);
674+
try {
675+
CloseableHttpResponse response = httpClient.execute(httpPost);
676+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
677+
XStream xstream = XStreamInitializer.getInstance();
678+
xstream.alias("xml", WxMpPrepayIdResult.class);
679+
WxMpPrepayIdResult wxMpPrepayIdResult = (WxMpPrepayIdResult) xstream.fromXML(responseContent);
680+
return wxMpPrepayIdResult;
681+
} catch (IOException e) {
682+
e.printStackTrace();
683+
}
684+
return new WxMpPrepayIdResult();
685+
}
694686

695-
Map<String, String> payInfo = new HashMap<String, String>();
696-
payInfo.put("appId", wxMpConfigStorage.getAppId());
697-
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
698-
payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
699-
payInfo.put("nonceStr", System.currentTimeMillis() + "");
700-
payInfo.put("package", "prepay_id=" + prepayId);
701-
payInfo.put("signType", "MD5");
702-
703-
String finalSign = WxCryptUtil.createSign(payInfo, wxMpConfigStorage.getPartnerKey());
704-
payInfo.put("sign", finalSign);
705-
return payInfo;
687+
@Override
688+
public Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String callbackUrl) {
689+
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(openId, outTradeNo, amt, body, tradeType, ip, callbackUrl);
690+
String prepayId = wxMpPrepayIdResult.getPrepay_id();
691+
if (prepayId == null || prepayId.equals("")) {
692+
throw new RuntimeException("get prepayid error");
706693
}
694+
695+
Map<String, String> payInfo = new HashMap<String, String>();
696+
payInfo.put("appId", wxMpConfigStorage.getAppId());
697+
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
698+
payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
699+
payInfo.put("nonceStr", System.currentTimeMillis() + "");
700+
payInfo.put("package", "prepay_id=" + prepayId);
701+
payInfo.put("signType", "MD5");
702+
703+
String finalSign = WxCryptUtil.createSign(payInfo, wxMpConfigStorage.getPartnerKey());
704+
payInfo.put("sign", finalSign);
705+
return payInfo;
706+
}
707707
}

0 commit comments

Comments
 (0)