前言:
如今看官们对“html支付成功界面源码”大约比较珍视,我们都想要了解一些“html支付成功界面源码”的相关文章。那么小编同时在网摘上网罗了一些对于“html支付成功界面源码””的相关资讯,希望姐妹们能喜欢,小伙伴们快快来了解一下吧!html页面选择微信支付后,超链接请求后台wxPayment()方法,例如链接请求:
location.href="../wxPayment?userName="+userName+"&phone="+phone+"&orderAmount="+orderAmount;
后台接收并处理如下:
第一步:public void wxPayment() {
HttpServletRequest request = getRequest();
HttpServletResponse response = getResponse();
String userName = getPara("userName");
String phone = getPara("phone");
String orderAmount = getPara("orderAmount");
try {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
String redirect_uri=URLEncoder.encode(/*你的网页授权域名*/, "UTF-8");
String url =
"?" +
"appid=" + /*你的APPID*/ +
"&redirect_uri=" + redirect_uri +
"?userName=" + URLEncoder.encode(userName) +
"%26phone=" + phone +
"%26orderAmount=" + orderAmount +
"&response_type=code" +
"&scope=snsapi_base" +
"&state=STATE" +
"#wechat_redirect";
response.sendRedirect(url.toString());
} catch (Exception e) {
log.error("微信支付出现异常", e);
}
}
此处需要注意:
网页授权域名必须在微信公众平台设置过,代码中必须加上你要跳转且获取参数的方法名,例如:网页授权域名/wxPay第一个参数必须是?挂载,后面的参数必须用%26进行转义,否则微信识别不了针对有汉字的参数,必须进行编码URLEncoder.encode(参数),否则微信识别不了
第二步:网页授权域名后面的方法,请求回调跳转的接口
public void wxPay() {
HttpServletRequest request = getRequest();
HttpServletResponse response = getResponse();
try {
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String code = request.getParameter("code");
String userName = request.getParameter("userName");
String phone = request.getParameter("phone");
String orderAmount = request.getParameter("orderAmount");
} catch (Exception e) {
log.error("微信支付出现异常", e);
}
}
这样一来,除了code,就可以获取到其他的订单参数啦,接下来就根据code获取openId进行下单处理吧!我们下次分享
标签: #html支付成功界面源码