mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
扫描支付 支持生成二维码URL字符串接口
This commit is contained in:
parent
edf558adde
commit
024d830947
@ -263,6 +263,19 @@ public interface WxPayService {
|
|||||||
*/
|
*/
|
||||||
byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength);
|
byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 扫码支付模式一生成二维码的方法
|
||||||
|
* 二维码中的内容为链接,形式为:
|
||||||
|
* weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
|
||||||
|
* 其中XXXXX为商户需要填写的内容,商户将该链接生成二维码,如需要打印发布二维码,需要采用此格式。商户可调用第三方库生成二维码图片。
|
||||||
|
* 文档详见: https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4
|
||||||
|
* </pre>
|
||||||
|
* @param productId 产品Id
|
||||||
|
* @return 生成的二维码URL连接
|
||||||
|
*/
|
||||||
|
String createScanPayQrcodeMode1(String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 扫码支付模式二生成二维码的方法
|
* 扫码支付模式二生成二维码的方法
|
||||||
|
@ -382,37 +382,44 @@ public class WxPayServiceImpl implements WxPayService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) {
|
public byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength) {
|
||||||
//weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
|
String content = createScanPayQrcodeMode1(productId);
|
||||||
|
return createQrcode(content, logoFile, sideLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String createScanPayQrcodeMode1(String productId){
|
||||||
|
//weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
|
||||||
StringBuilder codeUrl = new StringBuilder("weixin://wxpay/bizpayurl?");
|
StringBuilder codeUrl = new StringBuilder("weixin://wxpay/bizpayurl?");
|
||||||
Map<String, String> params = Maps.newHashMap();
|
Map<String, String> params = Maps.newHashMap();
|
||||||
params.put("appid", this.getConfig().getAppId());
|
params.put("appid", this.getConfig().getAppId());
|
||||||
params.put("mch_id", this.getConfig().getMchId());
|
params.put("mch_id", this.getConfig().getMchId());
|
||||||
params.put("product_id", productId);
|
params.put("product_id", productId);
|
||||||
params.put("time_stamp", String.valueOf(System.currentTimeMillis()));
|
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));//这里需要秒,10位数字
|
||||||
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
|
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
|
||||||
|
|
||||||
String sign = this.createSign(params);
|
String sign = this.createSign(params);
|
||||||
params.put("sign", sign);
|
params.put("sign", sign);
|
||||||
|
|
||||||
|
|
||||||
for (String key : params.keySet()) {
|
for (String key : params.keySet()) {
|
||||||
codeUrl.append(key + "=" + params.get(key) + "&");
|
codeUrl.append(key + "=" + params.get(key) + "&");
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = codeUrl.toString().substring(0, codeUrl.length() - 1);
|
String content = codeUrl.toString().substring(0, codeUrl.length() - 1);
|
||||||
if (sideLength == null || sideLength < 1) {
|
log.debug("扫码支付模式一生成二维码的URL:{}",content);
|
||||||
return QrcodeUtils.createQrcode(content, logoFile);
|
return content;
|
||||||
}
|
|
||||||
|
|
||||||
return QrcodeUtils.createQrcode(content, sideLength, logoFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength) {
|
public byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength) {
|
||||||
if (sideLength == null || sideLength < 1) {
|
return createQrcode(codeUrl, logoFile, sideLength);
|
||||||
return QrcodeUtils.createQrcode(codeUrl, logoFile);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return QrcodeUtils.createQrcode(codeUrl, sideLength, logoFile);
|
private byte[] createQrcode(String content, File logoFile, Integer sideLength) {
|
||||||
|
if (sideLength == null || sideLength < 1) {
|
||||||
|
return QrcodeUtils.createQrcode(content, logoFile);
|
||||||
|
}
|
||||||
|
return QrcodeUtils.createQrcode(content, sideLength, logoFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void report(WxPayReportRequest request) throws WxErrorException {
|
public void report(WxPayReportRequest request) throws WxErrorException {
|
||||||
|
Loading…
Reference in New Issue
Block a user