Skip to content

Commit 024d830

Browse files
committed
扫描支付 支持生成二维码URL字符串接口
1 parent edf558a commit 024d830

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,19 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
262262
* @return 生成的二维码的字节数组
263263
*/
264264
byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength);
265+
266+
/**
267+
* <pre>
268+
* 扫码支付模式一生成二维码的方法
269+
* 二维码中的内容为链接,形式为:
270+
* weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
271+
* 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。
272+
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4
273+
* </pre>
274+
* @param productId 产品Id
275+
* @return 生成的二维码URL连接
276+
*/
277+
String createScanPayQrcodeMode1(String productId);
265278

266279
/**
267280
* <pre>

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceImpl.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,37 +382,44 @@ public WxEntPayQueryResult queryEntPay(String partnerTradeNo) throws WxErrorExce
382382

383383
@Override
384384
public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) {
385-
//weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
385+
String content = createScanPayQrcodeMode1(productId);
386+
return createQrcode(content, logoFile, sideLength);
387+
}
388+
389+
@Override
390+
public String createScanPayQrcodeMode1(String productId){
391+
//weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
386392
StringBuilder codeUrl = new StringBuilder("weixin://wxpay/bizpayurl?");
387393
Map<String, String> params = Maps.newHashMap();
388394
params.put("appid", this.getConfig().getAppId());
389395
params.put("mch_id", this.getConfig().getMchId());
390396
params.put("product_id", productId);
391-
params.put("time_stamp", String.valueOf(System.currentTimeMillis()));
397+
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));//这里需要秒,10位数字
392398
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
393399

394400
String sign = this.createSign(params);
395401
params.put("sign", sign);
396402

403+
397404
for (String key : params.keySet()) {
398405
codeUrl.append(key + "=" + params.get(key) + "&");
399406
}
400407

401408
String content = codeUrl.toString().substring(0, codeUrl.length() - 1);
402-
if (sideLength == null || sideLength < 1) {
403-
return QrcodeUtils.createQrcode(content, logoFile);
404-
}
405-
406-
return QrcodeUtils.createQrcode(content, sideLength, logoFile);
409+
log.debug("扫码支付模式一生成二维码的URL:{}",content);
410+
return content;
407411
}
408412

409413
@Override
410414
public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength) {
411-
if (sideLength == null || sideLength < 1) {
412-
return QrcodeUtils.createQrcode(codeUrl, logoFile);
415+
return createQrcode(codeUrl, logoFile, sideLength);
416+
}
417+
418+
private byte[] createQrcode(String content, File logoFile, Integer sideLength) {
419+
if (sideLength == null || sideLength < 1) {
420+
return QrcodeUtils.createQrcode(content, logoFile);
413421
}
414-
415-
return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile);
422+
return QrcodeUtils.createQrcode(content, sideLength, logoFile);
416423
}
417424

418425
public void report(WxPayReportRequest request) throws WxErrorException {

0 commit comments

Comments
 (0)