微信授权登陆重定向到指定页面,微信公众号内调微信支付,H5跳小程序支付

微信授权登陆,授权获取code,

微信提供的snsapi_userinfo可以获取微信用户的信息,snsapi_base只能获取到openId;
document.location.replace(‘https://open.weixin.qq.com/connect/oauth2/authorize?appid=’ + “后台提供的appid” + ‘&redirect_uri=’ + encodeURIComponent(‘重定向的地址,须在公众号配置指定页面加/#/子页面’) + ‘&response_type=code&scope=snsapi_userinfo&state=’ + ‘123’ + ‘#wechat_redirect’)
获取code请求后台接口,还回绑定数据,token;

微信支付

首先微信授权登陆,授权获取code,用co’de跟订单id去请求后台接口获取微信支付的参数

微信支付代码
onBridgeReady(){
WeixinJSBridge.invoke(
‘getBrandWCPayRequest’, {
“appId”:“xxxxxxxxxxx”, //公众号名称,由商户传入
“timeStamp”:“1552964480”, //时间戳,自1970年以来的秒数
“nonceStr”:“xxxxxxxxxxxxx”, //随机串
“package”:“prepay_id=xxxxxxxxxxxxxxxxxxx”,
“signType”:“MD5”, //微信签名方式:
“paySign”:“xxxxxxxxxxxxxxxxxxxxxxx” //微信签名
},
function(res){
alert(res.err_code+res.err_desc+res.err_msg,“cuowu”)
if(res.err_msg == “get_brand_wcpay_request:ok” ){
console.log(res,“支付成共”)
// 使用以上方式判断前端返回,微信团队郑重提示:
//res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
}else{
console.log(res,“xxxxxxxxxxx”)
}
});
}
patMent(){
console.log(111111111111111111111111111)
if (typeof WeixinJSBridge == “undefined”){
if( document.addEventListener ){
document.addEventListener(‘WeixinJSBridgeReady’, this.onBridgeReady(), false);
}else if (document.attachEvent){
document.attachEvent(‘WeixinJSBridgeReady’, this.onBridgeReady());
document.attachEvent(‘onWeixinJSBridgeReady’, this.onBridgeReady());
}
}else{
this.onBridgeReady();
}
支付成功完成

微信支付中的H5调小程序支付

首先判断是不是在小程序里面
let ua = window.navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == ‘micromessenger’){
let JSonData = {
orderId:订单id,
token:登陆的token
}
wx.miniProgram.getEnv((res)=>{
if (res.miniprogram) {
// alert(“在小程序里”);
// 去微信小程序的页面带参数
wx.miniProgram.navigateTo({url: ‘/pages/wxpay/wxpay?JSon=’+JSON.stringify(JSonData)})
} else {
//先获取appid;在调取微信的授权
alert(“在微信里”);
//做微信支付
}
})
}else{
// 做h5支付
alert(‘不在微信里’);
}
小程序里面,
onLoad: function (options) {
首先解析传过来的参数,
wx.login({ //首先登陆授权
success(res) { //登陆成功
let code = res.code; //获取到code
if (!!code) { //获取到code的值
wx.request({
url: API.apiDomain + ‘/apis/activity/payWithWeixin’, // 后台接口
data: {
“appid”: “微信提供的appid”,
“id”: H5传来的订单Id,
“jsCode”: code,//登陆成功授权获取到code
},
header: {
Authorization: "Bearer " + H5传来的订单token
},
method: “POST”,
success(payRes) {
console.log(payRes, “askdaskdkask”)
if (payRes.data.status == true) {//数据请求成功,得到支付的参数
wx.hideLoading();
wx.requestPayment({ // 发起支付
timeStamp: payRes.data.data.timeStamp, //生成签名的时间戳
nonceStr: payRes.data.data.nonce_str, //生成签名的随机串,长度为32个字符以下。
package: “prepay_id=”+payRes.data.data.prepayId, //统一下单接口返回的 prepay_id 参数值
signType: ‘MD5’, //签名类型,默认为MD5,支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致
paySign: payRes.data.data.sign, //签名,具体签名方案参见微信公众号支付帮助文档;
success: function (res) {
// success
console.log(res,“我支付了”);
}
fail: function (res) {
// success
console.log(res,“我支付失败了”);
}
})
} else {
wx.showModal({
showCancel: false,
title: payRes.data.message
})
}
},
})
} else {
wx.showModal({
showCancel: false,
title: “获取微信登录信息错误”,
icon: ‘success’,
})
}
}
})
}

这是个人在做授权登陆,支付的代码

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值