1. 程式人生 > >如何獲取到微信公眾裡面的code

如何獲取到微信公眾裡面的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 }