H5商城在微信APP里支付

[b]前言:[/b] :arrow: jsapi支付方式,必须是关注公众号,后才能掉用微信支付,而作为非公众号的h5画面需要采用js sdk的方式唤起微信支付。

[b]这里推荐微信公众平台测试链接:[/b]
[url]http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login[/url]
[img]http://dl2.iteye.com/upload/attachment/0126/3997/fe081531-d30b-3fe1-852a-6089267083aa.png[/img]
[img]http://dl2.iteye.com/upload/attachment/0126/3999/4abf9282-dfae-362c-bb18-8716d015073a.png[/img]

[b]1.获取code[/b]
前台get方式即可,或在后台
https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx87a416348df09713&redirect_uri=http%3A%2F%2F10.88.75.139%3A8082%2Fcheckout%2Fguest&response_type=code&scope=snsapi_base&state=1#wechat_redirect
这里redirect_uri必须是urlencode

[b]2.根据appid,secret,code获取openId[/b]
在前台get:
https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx87********f09713&secret=85327124638********963b5a50c&code=031mBHO10Uya2C1wPzM104zIO10mBHOm&grant_type=authorization_code
或在后台:
			WechatQueryCommand queryCommand = prepareWechatQueryCommand(variableMap);
if(WechatQueryCommand.QUERY_METHOD_GET.equals(queryCommand.getQueryMethod())) {
return URLConnectionUtil.getResponseBodyAsString(prepareWechatQueryCommand(variableMap).toQueryString());
} else {
return WechatUtil.post(queryCommand.getQueryUri(), queryCommand.toQueryString());
}

以上返回参数里还包括token

[b]3.调用微信统一下单接口(会遇到问题)[/b]
[img]http://dl2.iteye.com/upload/attachment/0126/4007/36220ddb-c8a5-3f7c-a91d-75346f68fe27.png[/img]
交易类型用jsapi,返回html直接
response.setContentType("text/html; charset=UTF-8"); 
PrintWriter out = response.getWriter();
out.print(html);
out.flush();
out.close();

会发现有问题
[img]http://dl2.iteye.com/upload/attachment/0126/3995/af99015e-5993-3eae-9a54-de4441914b67.png[/img]

[b]4.采用js-sdk唤起微信支付服务[/b]

你可能感兴趣的:(电商-支付相关)