function payEnvHandle() {
var isInWeiXinApp = window.navigator.userAgent.toLowerCase().search(/MicroMessenger/i) > -1;
var isInAliPayApp = window.navigator.userAgent.toLowerCase().search(/AlipayClient/i) > -1;
}
微信支付
微信环境,首先获取这个url链接是否有授权的code
1.如果有直接生成订单信息进行微信支付
2.如果没有code,则进行微信授权进行重定向
var code = GetQueryString('code');
if (!code) {
weixinAuth();
}
function GetQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
var r = window.location.search.substr(1).match(reg);
if (r != null) return decodeURI(r[2]);
return null;
}
function weixinAuth() {
let urlNow = encodeURIComponent(window.location.href);
let scope = 'snsapi_base';
let appid = "11111111111111";
let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=STATE&connect_redirect=1#wechat_redirect`;
window.location.replace(url);
}
生成订单信息得到微信位置所需要的支付参数,然后唤醒微信支付
function wxPay(data) {
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener(
"WeixinJSBridgeReady",
onBridgeReady(data),
false
);
} else if (document.attachEvent) {
document.attachEvent("WeixinJSBridgeReady", onBridgeReady(data));
document.attachEvent("onWeixinJSBridgeReady", onBridgeReady(data));
}
} else {
onBridgeReady(data);
}
}
function onBridgeReady(data) {
WeixinJSBridge.invoke(
"getBrandWCPayRequest", {
"appId": data.appId,
"timeStamp": data.timeStamp,
"nonceStr": data.nonceStr,
"package": data.package,
"signType": data.signType,
"paySign": data.paySign
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
}else{}
}
);
}
支付宝支付
支付宝环境(参考其他的聚合支付流程,一直查询订单状态,重定向到阿里支付)
function aliPay() {
var timer = setInterval(function () {
queryOrder();
}, 5000);
window.location.href =
"alipays://platformapi/startapp?saId=10000007&qrcode=''"
}
function queryOrder(){
}