1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 微信公众号通过H5网页获取openid的代码流程泳道图以及代码

微信公众号通过H5网页获取openid的代码流程泳道图以及代码

时间:2020-12-14 15:14:47

相关推荐

微信公众号通过H5网页获取openid的代码流程泳道图以及代码

页面代码举例

scope=snsapi_base 静默只获取openid

var wxauthurl = "https://open./connect/oauth2/authorize";let wx_code = getUrlParam("code"); // 截取url中的codeconsole.log("wx_code ", wx_code)if (!wx_code) {const pathStr = window.location.hrefconsole.log('cururl ', pathStr)window.location.href = wxauthurl+'?appid='+appid+'&redirect_uri=' + encodeURIComponent(pathStr) + '&response_type=code&scope=snsapi_base&state=1#wechat_redirect'; } else {request({method: 'GET',url: '/wechat/base/getOpenid/'+wx_code,header: null,data,success(res) {console.log("res", res)const responseData = res.data as IResponseData;const { code, token, msg } = responseData;if (code === 200) {console.log('get openid success')}}})}export const getUrlParam = ( name:string ) => {var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");var r = window.location.search.substr(1).match(reg);if (r != null) return unescape(r[2]);return null;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。