欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

uniapp中h5網(wǎng)頁微信公眾號授權(quán) - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏壧峁┍憬莸闹С郑?

您當(dāng)前位置>首頁 » 新聞資訊 » 公眾號相關(guān) >

uniapp中h5網(wǎng)頁微信公眾號授權(quán)

發(fā)表時間:2020-10-19

發(fā)布人:葵宇科技

瀏覽次數(shù):297

uniapp微信網(wǎng)頁授權(quán)

  • uniapp中h5網(wǎng)頁微信公眾號授權(quán)
    • 主要代碼
    • 獲取code返回的code截取代碼

uniapp中h5網(wǎng)頁微信公眾號授權(quán)

微信官方文檔–>網(wǎng)頁授權(quán)
uniapp中h5網(wǎng)頁微信公眾號授權(quán)步驟:
1.采用用戶授權(quán)獲取code
2.把code傳給后端后端獲取openid 以及是否關(guān)注公眾號判斷
3.沒有關(guān)注跳轉(zhuǎn)至關(guān)注公眾號頁面

主要代碼

//判斷用戶是否是微信環(huán)境
if (isWechat()) {
				let code = getUrlParam("code"); //是否存在code 截取code代碼 授權(quán)會返回code需要截取鏈接中code
				let local = window.location.href;
				if (code == null || code === "") {
					//不存在就打開上面的地址進(jìn)行授權(quán)
					window.location.href =
						`https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=url&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`;
				//appid填寫你的appid 	redirect_uri填寫請求成功后回調(diào)地址						
				} else {
					that.code = code;
					//把code傳給后端判斷用戶是否關(guān)注相對應(yīng)的公眾號
					uni.request({
						url: 'url',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						data: {
							code: that.code
						},
						method: 'GET',
						success: (res) => {
							//201沒有關(guān)注公眾號 跳轉(zhuǎn)關(guān)注頁面
							if (res.data == 201) {
								window.location.href =
									`https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=wechatbiz#wechat_redirect`;
								//_biz的獲取通過登錄微信公眾平臺 在頭像那里右擊查看源碼 找到 uin: "658565",uin_base64: "",_biz的值等于uin_base64就可以了
							} else { //關(guān)注了可以進(jìn)行下一步
								uni.request({
									url: 'url',
									header: {
										'content-type': 'application/x-www-form-urlencoded'
									},
									method: 'GET',
									success: (ti) => {
									
									}
								})
							}
						},
					})
				}
			}else{
				uni.showModal({
					title:'請?jiān)谖⑿糯蜷_',
					content:'請?jiān)谖⑿糯蜷_本網(wǎng)頁'
				})
			}

獲取code返回的code截取代碼

// 判斷公眾號截取code
	const getUrlParam = (name) => {
		let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		let r = window.location.search.substr(1).match(reg);
		if (r != null) {
			return unescape(r[2]);
		}
		return null;
	}

相關(guān)案例查看更多