1.微信支付中静默调起支付:必须等到微信js加载完成,所以用下面注释的方式不对。
<script type="text/javascript">
var $appid='${nativeMap.appId}';
var $timeStamp='${nativeMap.timeStamp}';
var $nonceStr='${nativeMap.nonceStr}';
var $package= '${nativeMap.Package}';
var $paySign='${nativeMap.paySign}';
function callpay(){
WeixinJSBridge.invoke('getBrandWCPayRequest',{
"appId" :$appid,
"timeStamp" :$timeStamp,
"nonceStr" : $nonceStr,
"package" : $package,
"signType" : "MD5",
"paySign" : $paySign
},function(res){
WeixinJSBridge.log(res.err_msg);
if(res.err_msg == "get_brand_wcpay_request:ok"){
//成功之后执行代码
}else{
//失败之后执行代码
}
});
}
document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
callpay();
// 通过下面这个API隐藏右上角按钮
//WeixinJSBridge.call('hideOptionMenu');
// 发送给好友
}, false);
/*
$(function(){
callpay();
}); */
</script>
2.支付链接必须在微信配置里面设置,在设置的目录下面才能支付成功,下面有颜色的部分和微信哪里设置配置一致
try {
// 用户授权页面跳转
String appid = WXConfig.PARAMETERS.APPID;
String redirect_url = basepath+"/pay/api/wxpay/"
+ oid + "?showwxpaytitle=1";
redirect_url = URLEncoder.encode(redirect_url, "UTF-8");
System.out.println(redirect_url);
System.out
.println(String
.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect",
appid, redirect_url));
response.sendRedirect(String
.format("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect",
appid, redirect_url));
} catch (IOException e) {
e.printStackTrace();
}