深蓝的一片海
深蓝的一片海
  • 发布:2021-03-24 17:12
  • 更新:2023-10-14 15:22
  • 阅读:1077

uniapp做微信公众号网页支付

分类:uni-app
const base_url = encodeURIComponent('xxxxxx/wx/index.html')// 前端域名  
        const wx_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxx+'&redirect_uri='+base_url+'&response_type=code&scope=snsapi_base&state=123#wechat_redirect'  
onLoad() {  
             // 获取URL 上code  

             if(!this.isWechat()){  
                   window.location.href="http://www." ;    
                  return  
             }   
               const code = this.getUrlParam('code')  
                // 判断是否存在code  
                if(code == null || code == '') {  
                    // 重新获取code  
                    // console.log(code)  
                   window.location.href = wx_url  
                } else {  
                    // 发送code             
                        this.postCode(code)  
                }  
            this.init()  
            var uanew = window.navigator.userAgent.toLowerCase();  
            if (uanew.match(/micromessenger/i) == 'micromessenger') {  
                //console.log('是微信客户端')    
                this.iswechat=false  
            } else {  
                //console.log('不是微信客户端')    
                this.iswechat=true  
            }  
        },  

method:{  

 // 解析URL 参数  
                    getUrlParam(name) {  
                        let reg = new RegExp('(^|&)'+ name + '=([^&]*)(&|$)')  
                        let r = window.location.search.substr(1).match(reg)  
                        if(r!=null){  
                            return unescape(r[2])  
                        }   
                        return null  
                    },  

    //判断是否在微信中  
            isWechat() {  
                var ua = window.navigator.userAgent.toLowerCase();  
                if (ua.match(/micromessenger/i) == 'micromessenger') {  
                    //console.log('是微信客户端')    
                    return true;  
                } else {  
                    //console.log('不是微信客户端')    
                    return false;  
                }  
            },  
}  

不懂的联系我(找昵称)

0 关注 分享

要回复文章请先登录注册

王翔

王翔

怎么联系
2023-10-14 15:22
2***@qq.com

2***@qq.com

谢谢,完美得解决继续搜索的情况
2021-05-12 09:12
6***@qq.com

6***@qq.com

除了标题,请问那一句话跟支付有关?
2021-04-09 17:46