如何获取到微信公众里面的code

mounted () {
this . openId = lscache . get ( 'openId' )
this . WxOpenIdInput . code = this . getQueryString ( 'code' )
if ( ! this . WxOpenIdInput . code ) {
// // 0注册微信链接地址
const authUrl = this . isValidauthUrl ( 0 )
window . location . href = authUrl
} else {
this . WeiXinClient . getOpenIdByCode ( this . WxOpenIdInput )
. then ( res => {
console . log ( res )
lscache . set ( 'openId' , res . openId )
lscache . set ( 'nickname' , res . nickname )
})
. catch ( res => {})
}
}
getQueryString ( name ) {
var reg = new RegExp ( '(^|&)' + name + '=([^&]*)(&|$)' , 'i' )
var r = window . location . search . substr ( 1 ). match ( reg )
if ( r != null ) {
return unescape ( r [ 2 ])
}
return null
}

猜你喜欢

转载自my.oschina.net/u/3407708/blog/2966824