我的微信怎么不能微信扫码支付回调了

微信支付和支付宝支付中的扫码支付,为什么不能由付款方设定价格?万一被多刷了怎么办? - 知乎183被浏览32159分享邀请回答52 条评论分享收藏感谢收起218 条评论分享收藏感谢收起查看更多回答其他回答(1)
这种情况你应该查一查微信API,看看能不能通过订单号返回二维码给你,
继续上次未完成的支付。
园豆:25064
&&&您需要以后才能回答,未注册用户请先。微信支付怎么弄(微信扫码支付步骤流程)
我的图书馆
微信支付怎么弄(微信扫码支付步骤流程)
  微信扫码支付怎么弄,微信扫码支付是怎么使用的,微信扫码支付二维码是怎么生成的呢?今天我们就来说说微信扫码支付功能是怎么开发的?  微信扫码支付步骤流程  用户扫描商户展示在各种场景的二维码进行支付。  步骤1:商户根据微信支付的规则,为不同商品生成不同的二维码,展示在各种场景,用于用户扫描购买。  步骤2:用户使用微信“扫一扫扫描二维码后,获取商品支付信息,引导用户完成支付。  步骤3:用户确认支付,输入支付密码。  步骤4:支付完成后会提示用户支付成功,商户后台得到支付成功的通知,然后进行发货处理。  微信支付扫码的二维码怎么生成  打开微信,点击右上角 加号 选择收钱,二维码就自动生成了,然后让别人扫你的二维码即可支付。  现在已经运用到排队点餐,商店买东西,参与到生活中的方方面面,已经取代了原生态的现金和刷卡支付这种繁杂过程。
TA的最新馆藏
喜欢该文的人也喜欢微信公众号开发之扫码支付 - 简书
微信公众号开发之扫码支付
欢迎留言、转发
微信极速开发系列文章:
上一篇文章介绍了微信提供的那些支付方式以及公众号支付
这篇文章我们来聊聊微信扫码支付(模式一以及模式二)
微信扫码支付文档
扫码支付分为以下两种方式:
【模式一】:商户后台系统根据微信支付规则链接生成二维码,链接中带固定参数productid(可定义为产品标识或订单号)。用户扫码后,微信支付系统将productid和用户唯一标识(openid)回调商户后台系统(需要设置支付回调URL),商户后台系统根据productid生成支付交易,最后微信支付系统发起用户支付流程。
【模式二】:商户后台系统调用微信支付生成预付交易,将接口返回的链接生成二维码,用户扫码后输入密码完成支付交易。注意:该模式的预付单有效期为2小时,过期后无法支付。
扫码支付模式一
1、设置支付回调URL
商户支付回调URL设置指引:进入公众平台--&微信支付--&开发配置--&扫码支付--&修改
如下图(来自官方文档)
扫码支付模式一
设置回调URL.png
在中扫码支付模式一的回调URL为http://域名[/项目名称]/pay/wxpay
2、根据微信支付规则链接生成二维码
2.1 生成二维码规则
二维码中的内容为链接,形式为:
weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX
详细的参数说明参考文档
商户ID(mch_id)如何获取
签名安全规则文档
在中 扫码支付模式一
生成二维码规则封装如下:
public String getCodeUrl(){
String url="weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXX&time_stamp=XXXXX&nonce_str=XXXXX";
String product_id="001";
String timeStamp=Long.toString(System.currentTimeMillis() / 1000);
String nonceStr=Long.toString(System.currentTimeMillis());
Map&String, String& packageParams = new HashMap&String, String&();
packageParams.put("appid", appid);
packageParams.put("mch_id", partner);
packageParams.put("product_id",product_id);
packageParams.put("time_stamp", timeStamp);
packageParams.put("nonce_str", nonceStr);
String packageSign = PaymentKit.createSign(packageParams, paternerKey);
return StringUtils.replace(url, "XXXXX", packageSign,appid,partner,product_id,timeStamp,nonceStr);
以上action 在中 访问地址为http://域名[/项目名称]/pay/getCodeUrl
其中 product_id 根据实际的业务逻辑可以当做参数传入
2.2 生成二维码并在页面上显示
根据2.1生成二维码规则生成了二维码中的内容(链接)来生成二维码。
商户可调用第三方库生成二维码图片
这里使用google 开源图形码工具Zxing
项目中引入相关的jar包 具体配置参考项目中的pom.xml
&!-- 版本号--&
&zxing.version&3.2.1&/zxing.version&
&!-- 开源多维码生成工具 --&
&dependency&
&groupId&com.google.zxing&/groupId&
&artifactId&core&/artifactId&
&version&${zxing.version}&/version&
&/dependency&
&dependency&
&groupId&com.google.zxing&/groupId&
&artifactId&javase&/artifactId&
&version&${zxing.version}&/version&
&/dependency&
封装的工具类为com.javen.kit.ZxingKit
* google 开源图形码工具Zxing使用
public class ZxingKit {
private static Log log = Log.getLog(ZxingKit.class.getSimpleName());
* Zxing图形码生成工具
* @param contents
* @param barcodeFormat
BarcodeFormat对象
* @param format
图片格式,可选[png,jpg,bmp]
* @param width
* @param height
* @param margin
边框间距px
* @param saveImgFilePath
存储图片的完整位置,包含文件名
public static Boolean encode(String contents, BarcodeFormat barcodeFormat, Integer margin,
ErrorCorrectionLevel errorLevel, String format, int width, int height, String saveImgFilePath) {
Boolean bool =
BufferedImage bufI
Map&EncodeHintType, Object& hints = new HashMap&EncodeHintType, Object&();
// 指定纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, errorLevel);
hints.put(EncodeHintType.MARGIN, margin);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
// contents = new String(contents.getBytes("UTF-8"), "ISO-8859-1");
BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, barcodeFormat, width, height, hints);
MatrixToImageConfig config = new MatrixToImageConfig(0xFFxFFFFFFFF);
bufImg = MatrixToImageWriter.toBufferedImage(bitMatrix, config);
bool = writeToFile(bufImg, format, saveImgFilePath);
} catch (Exception e) {
e.printStackTrace();
* @param srcImgFilePath
要解码的图片地址
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
Result result =
File srcFile = new File(srcImgFilePath);
image = ImageIO.read(srcFile);
if (null != image) {
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable&DecodeHintType, String& hints = new Hashtable&DecodeHintType, String&();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
result = new MultiFormatReader().decode(bitmap, hints);
log.debug("Could not decode image.");
} catch (Exception e) {
e.printStackTrace();
} finally {
* 将BufferedImage对象写入文件
* @param bufImg
BufferedImage对象
* @param format
图片格式,可选[png,jpg,bmp]
* @param saveImgFilePath
存储图片的完整位置,包含文件名
@SuppressWarnings("finally")
public static Boolean writeToFile(BufferedImage bufImg, String format, String saveImgFilePath) {
Boolean bool =
bool = ImageIO.write(bufImg, format, new File(saveImgFilePath));
} catch (Exception e) {
e.printStackTrace();
} finally {
public static void main(String[] args) {
String saveImgFilePath = "D://zxing.png";
Boolean encode = encode("我是Javen205", BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200,
saveImgFilePath);
if (encode) {
Result result = decode(saveImgFilePath);
String text = result.getText();
System.out.println(text);
OK 上面就是生成支付二维码的部分,接下来就是要将二维码显示在页面上,于是就有了下面的代码:com.javen.weixin.controller.WeixinPayController.getPayQRCode()
src\main\webapp\view\payQRCode.jsp
* 生成支付二维码(模式一)并在页面上显示
public void scanCode1(){
//获取扫码支付(模式一)url
String qrCodeUrl=getCodeUrl();
System.out.println(qrCodeUrl);
//生成二维码保存的路径
String name = "payQRCode.png";
Boolean encode = ZxingKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200,
PathKit.getWebRootPath()+File.separator+"view"+File.separator+name );
if (encode) {
//在页面上显示
setAttr("payQRCode", name);
render("payQRCode.jsp");
JSP 部分代码如下
&img alt="" src="&%=path %&/view/${payQRCode}"&
最终生成二维码访问地址为http://域名[/项目名称]/pay/scanCode1
以上就是微信扫码支付(模式一)生成支付二维码的全过程
3、扫码回调商户支付URL
用户扫码后,微信支付系统将productid和用户唯一标识(openid)回调商户后台系统。
此回调的URL为上文设置支付回调的URL。特别要注意的是返回参数是xml输入流
HttpServletRequest request = getRequest();
* 获取用户扫描二维码后,微信返回的信息
InputStream inStream = request.getInputStream();
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
outSteam.write(buffer, 0, len);
outSteam.close();
inStream.close();
String result
= new String(outSteam.toByteArray(),"utf-8");
System.out.println("callBack_xml&&&"+result);
&appid&&![CDATA[wx5ef64cd]]&&/appid&
&openid&&![CDATA[o_pncsidC-pRRfCP4zj98h6slREw]]&&/openid&
&mch_id&&![CDATA[商户ID]]&&/mch_id&
&is_subscribe&&![CDATA[Y]]&&/is_subscribe&
&nonce_str&&![CDATA[gT5NJAlv9eXawn1j]]&&/nonce_str&
&product_id&&![CDATA[001]]&&/product_id&
&sign&&![CDATA[D2BDBB43D66]]&&/sign&
4、根据回调参数生成预付订单进行支付
根据回调参数调用生成预支付交易的prepay_id
prepay_xml&&&
&xml&&return_code&&![CDATA[SUCCESS]]&&/return_code&
&return_msg&&![CDATA[OK]]&&/return_msg&
&appid&&![CDATA[微信的appid]]&&/appid&
&mch_id&&![CDATA[商户ID]]&&/mch_id&
&nonce_str&&![CDATA[p46NAoD82eAH2d9j]]&&/nonce_str&
&sign&&![CDATA[33DC8F72D]]&&/sign&
&result_code&&![CDATA[SUCCESS]]&&/result_code&
&prepay_id&&![CDATA[wx007cb1cbe40b]]&&/prepay_id&
&trade_type&&![CDATA[NATIVE]]&&/trade_type&
&code_url&&![CDATA[weixin://wxpay/bizpayurl?pr=QCLqJIG]]&&/code_url&
商户后台系统将prepay_id返回给微信支付系统,微信支付系统根据交易会话标识,发起用户端授权支付流程。
* 发送信息给微信服务器
Map&String, String& payResult = PaymentKit.xmlToMap(xmlResult);
String return_code = payResult.get("return_code");
String result_code = payResult.get("result_code");
if (StrKit.notBlank(return_code) && StrKit.notBlank(result_code) && return_code.equalsIgnoreCase("SUCCESS")&&result_code.equalsIgnoreCase("SUCCESS")) {
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String prepay_id = payResult.get("prepay_id");
Map&String, String& prepayParams = new HashMap&String, String&();
prepayParams.put("return_code", "SUCCESS");
prepayParams.put("appId", appid);
prepayParams.put("mch_id", mch_id);
prepayParams.put("nonceStr", System.currentTimeMillis() + "");
prepayParams.put("prepay_id", prepay_id);
String prepaySign =
if (sign.equals(packageSign)) {
prepayParams.put("result_code", "SUCCESS");
prepayParams.put("result_code", "FAIL");
prepayParams.put("err_code_des", "订单失效");
//result_code为FAIL时,添加该键值对,value值是微信告诉客户的信息
prepaySign = PaymentKit.createSign(prepayParams, paternerKey);
prepayParams.put("sign", prepaySign);
String xml = PaymentKit.toXml(prepayParams);
log.error(xml);
renderText(xml);
5、支付结果通用通知
对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,微信会通过一定的策略定期重新发起通知,尽可能提高通知的成功率,但微信不保证通知最终能成功。 (通知频率为15/15/30/180/00/,单位:秒)注意:同样的通知可能会多次发送给商户系统。商户系统必须能够正确处理重复的通知。推荐的做法是,当收到通知进行处理时,首先检查对应业务数据的状态,判断该通知是否已经处理过,如果没有处理过再进行处理,如果处理过直接返回结果成功。在对业务数据进行状态检查和处理之前,要采用数据锁进行并发控制,以避免函数重入造成的数据混乱。特别提醒:商户系统对于支付结果通知的内容一定要做签名验证,防止数据泄漏导致出现“假通知”,造成资金损失。技术人员可登进微信商户后台扫描加入接口报警群。
此通知接收地址为生成预付订单时设置的notify_url 。在中通知默认的地址为http://域名[/项目名称]/pay/pay_notify
以上是微信扫码支付模式一的全过程。
扫码支付模式二
模式二与模式一相比,流程更为简单,不依赖设置的回调支付URL。商户后台系统先调用微信支付的统一下单接口,微信后台系统返回链接参数code_url,商户后台系统将code_url值生成二维码图片,用户使用微信客户端扫码后发起支付。注意:code_url有效期为2小时,过期后扫码不能再发起支付。
微信支付的统一下单接口具体实现上文也有提及到,如果还不是很清楚可以看
com.javen.weixin.controller.WeixinPayController中的scanCode2 以及
以下是调用预付订单返回的xml
&xml&&return_code&&![CDATA[SUCCESS]]&&/return_code&
&return_msg&&![CDATA[OK]]&&/return_msg&
&appid&&![CDATA[wx5ef64cd]]&&/appid&
&mch_id&&![CDATA[]]&&/mch_id&
&nonce_str&&![CDATA[XdVf2zXLErIHRfJn]]&&/nonce_str&
&sign&&![CDATA[CC4A9E4C3337]]&&/sign&
&result_code&&![CDATA[SUCCESS]]&&/result_code&
&prepay_id&&![CDATA[wx]]&&/prepay_id&
&trade_type&&![CDATA[NATIVE]]&&/trade_type&
&code_url&&![CDATA[weixin://wxpay/bizpayurl?pr=WWOXnrb]]&&/code_url&
其中code_url 就是生成二维码的链接
String qrCodeUrl = result.get("code_url");
String name = "payQRCode1.png";
Boolean encode = ZxingKit.encode(qrCodeUrl, BarcodeFormat.QR_CODE, 3, ErrorCorrectionLevel.H, "png", 200, 200,
PathKit.getWebRootPath()+File.separator+"view"+File.separator+name );
if (encode) {
//在页面上显示
setAttr("payQRCode", name);
render("payQRCode.jsp");
扫码即可进行支付,code_url有效期为2小时,过期后扫码不能再发起支付
最终生成二维码访问地址为http://域名[/项目名称]/pay/scanCode2
码字完毕,以上就是微信扫码支付(模式一、模式二)的详细介绍。
欢迎留言、转发微信极速开发系列文章:
后续更新预告1、刷卡支付2、微信红包3、企业转账
专注Android、微信开发。公众号javenlife}

我要回帖

更多关于 微信扫码支付 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信