H5商城在微信APP里支付

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

这里推荐微信公众平台测试链接:
http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login



1.获取code
前台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

2.根据appid,secret,code获取openId
在前台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

3.调用微信统一下单接口(会遇到问题)

交易类型用jsapi,返回html直接
response.setContentType("text/html; charset=UTF-8"); 
				PrintWriter out = response.getWriter(); 
				out.print(html);
				out.flush();  
		        out.close();

会发现有问题


4.采用js-sdk唤起微信支付服务

猜你喜欢

转载自572327713.iteye.com/blog/2388251