uniapp公众号分销商城从0到1微信获取code02-微信公众号分销商城系统开发-小程序分销系统开发
1.
微信获取code传到后段获取openid等信息
2.getWxCode.js【获取微信code的js】
functiongetcode(redirect_uri){leturlwindow.location.href;letwxurl"https://open.weixin.qq.com/connect/oauth2/authorize?appidwxa4a0edf925e02959"+"response_typecodescopesnsapi_base"+"redirect_uri"+redirect_uri+"state123#wechat_redirect";window.location.hrefwxurl;}functiongetUrlParam(name){varregnewRegExp("(^|)"+name+"([^]*)(|$)","i");varparamswindow.location.search.substr(1).replace("__","");varrparams.match(reg);if(r!null)returnunescape(r[2]);returnnull;}exportdefault{getcode:function(redirect_uri){returngetcode(redirect_uri)},getUrlParam:function(name){returngetUrlParam(name)}}3.index.vue倒入
let_self;importwxcodefrom"@/common/getWxCode.js";4.onload调用
onLoad(){_selfthis;if(wxcode.getUrlParam("code")){_self.getOpenid(wxcode.getUrlParam("code"));}else{wxcode.getcode(window.location.href);}},5.【有时间持续更新中~】
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

