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.

【有时间持续更新中~】

TAG标签: uniapp公众号分销商城从0到1微信获取code02微信公众号分销商城系统开发小程序分销系统开发

http://www.xiaochengxub.com/read-96392.html