精品秘无码一区二区三区老师-精品秘一区二三区免费雷安-精品蜜桃秘一区二区三区-精品蜜桃秘一区二区三区粉嫩-精品蜜桃一区二区三区-精品蜜臀国产aⅴ一区二区三区

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開(kāi)發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

C#+UniApp實(shí)現(xiàn)微信授權(quán)登錄

admin
2025年1月15日 8:32 本文熱度 373
一、效果展示

二:H5登錄頁(yè)面

<template>	<view class="content">		<image class="img" src="../../static/images/logo.png" mode=""></image>		<form>			<view class="list" style="margin-top: 80rpx;">				<input class="uni-input maininput" v-model="name" placeholder="用戶(hù)名" />				<text class="bl_icon_yonghu"></text>			</view>			<view class="list texttop">				<input class="uni-input maininput" type="password" v-model="password" placeholder="密碼" />				<text class="bl_icon_mima"></text>			</view>			<view>				<button type="primary" class="buttoncolor martop" @click="formSubmit">登陸</button>			</view>			<view class="bottom-side-otherLogin" @click="getWeChatCode">				<text>微信登錄</text>				<image src="../../static/images/wx.png"></image>			</view>		</form>	</view></template><script>	export default {		data() {			return {			}		},		onLoad() {			//打開(kāi)系統(tǒng),進(jìn)入微信授權(quán)頁(yè)面			let wxCode = uni.getStorageSync('wxCode')			if(wxCode==null)			{				this.getWeChatCode()			}		},		methods: {			//請(qǐng)求微信接口,用來(lái)獲取code			getWeChatCode() {				let local = encodeURIComponent('http://' + window.location.host +				'/#/pages/wxlogin/wxlogin'); //獲取當(dāng)前頁(yè)面地址作為回調(diào)地址				let appid = ''   //公眾號(hào)appid				//通過(guò)微信官方接口獲取code之后,會(huì)重新刷新設(shè)置的回調(diào)地址【redirect_uri】				let code = this.getUrlCode('code')				//如果沒(méi)有code 去獲取code				if (code == null) {					uni.setStorageSync('isLogin', 1)					window.location.href =						"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +						appid +						"&redirect_uri=" +						local +						"&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";				} else {					//this.checkWeChatCode(code) //通過(guò)微信官方接口獲取code之后,會(huì)重新刷新設(shè)置的回調(diào)地址【redirect_uri】				}			}		}	}</script>

二:H5用戶(hù)同意授權(quán),獲取code

<template>	<view>		微信授權(quán)登錄中...	</view></template><script>export default {	data() {		return {			openid'',			isBind'',		}	},	onLoad() {		let isLogin = uni.getStorageSync('isLogin')		if (isLogin == 1) {			let code = this.getUrlCode('code')			if (code != null) {				this.checkWeChatCode(code)				uni.setStorageSync('wxCode', code)			}		}	},	methods: {		//方法:用來(lái)提取code		getUrlCode(name) {			return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||				[, ''				])[1]				.replace(/\+/g, '%20')) || null		},		//檢查瀏覽器地址欄中微信接口返回的		checkWeChatCode(code) {			if (code) {				this.getOpenidAndUserinfo(code)			}		},		//把code傳遞給后臺(tái)接口,靜默登錄		getOpenidAndUserinfo(code) {			let that = this;			uni.request({				url: that.websiteUrl + '/api/Wx/WechatLogin',				method: 'GET',				data: {					code: code				},				header: {					'content-type': 'application/x-www-form-urlencoded' //自定義請(qǐng)求頭信息				},				success: function(res) {					if (res.statusCode == 200) {						if (res.data.errCode == 0) {							that.openid = res.data.result.Openid;							that.isBind = res.data.result.IsBind;							uni.setStorageSync('openid', that.openid);							uni.setStorageSync('headimgurl', res.data.result.Headimgurl);							//綁定到系統(tǒng)用戶(hù)表						}					}				},				fail: function(data) {				}			})		}	}}</script>

三:后端獲取微信用戶(hù)信息

?

/// <summary>  /// 獲取微信用戶(hù)信息/// </summary>  /// <returns></returns>[HttpGet]public ApiResponse WechatLogin(string code){	try {		if (!string.IsNullOrEmpty(code))		{			string openid = string.Empty;			string headimgurl = string.Empty;			if (CacheHelper.Get(code)!=null)			{				openid = CacheHelper.Get(code).ToString();			}			else			{				//根據(jù)appid,secret,code取到用戶(hù)的全部信息  				Dictionary<string, object> dic = GetUserInfoByCode(AppId, AppSecret, code.Trim());				if (dic.ContainsKey("errcode"))				{					return BaseApiResponse.ApiError(dic["errmsg"].ToString());				}				openid = dic["openid"].ToString();				headimgurl = dic["headimgurl"].ToString();				CacheHelper.Insert(code, openid);			}			//根據(jù)微信唯一標(biāo)識(shí)openid 去數(shù)據(jù)庫(kù)判斷是否存在			UserDao userDao = new UserDao();			UserEntity userEntity = userDao.GetByOpenid(openid);			Dictionary<string, string> userDic = new Dictionary<string, string>();			if (userEntity != null)			{				userDic.Add("UserName", userEntity.Code);				userDic.Add("PassWord", EncryptCommon.DecryptStr(userEntity.Password));				userDic.Add("Openid", openid);				userDic.Add("IsBind""1");				userDic.Add("Headimgurl", headimgurl);			}			else			{				userDic.Add("UserName""");				userDic.Add("PassWord""");				userDic.Add("Openid", openid);				userDic.Add("IsBind""0");				userDic.Add("Headimgurl", headimgurl);			}			return BaseApiResponse.ApiSuccess(userDic);		}		return BaseApiResponse.ApiError("code不能為空!");	}	catch(Exception ex){		return BaseApiResponse.ApiError(ex.ToString());	}}
/// <summary>  ///用code換取獲取用戶(hù)信息(包括非關(guān)注用戶(hù)的)(此access_token是網(wǎng)頁(yè)授權(quán)的和普通無(wú)關(guān))  /// </summary>  /// <param name="Appid"></param>  /// <param name="Appsecret"></param>  /// <param name="Code">回調(diào)頁(yè)面帶的code參數(shù)</param>  /// <returns>獲取用戶(hù)信息(json格式)</returns>  public static Dictionary<string, object> GetUserInfoByCode(string Appid, string Appsecret, string Code){       //通過(guò)code換取網(wǎng)頁(yè)授權(quán)access_token	JavaScriptSerializer Jss = new JavaScriptSerializer();	string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", Appid, Appsecret, Code);	string ReText = Tools.WebRequestPostOrGet(url, "");//post/get方法獲取信息  	Dictionary<string, object> DicText = (Dictionary<string, object>)Jss.DeserializeObject(ReText);	if (!DicText.ContainsKey("openid"))	{		return DicText;	}	else	{	        //拉取用戶(hù)信息(需scope為 snsapi_userinfo)		Dictionary<string, object> respDic = (Dictionary<string, object>)Jss.DeserializeObject(Tools.WebRequestPostOrGet("https://api.weixin.qq.com/sns/userinfo?access_token=" + DicText["access_token"] + "&openid=" + DicText["openid"] + "&lang=zh_CN", ""));		return respDic;	}}


閱讀原文:原文鏈接


該文章在 2025/1/15 10:17:20 編輯過(guò)
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專(zhuān)業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車(chē)隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開(kāi)發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類(lèi)企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷(xiāo)售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶(hù)的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 综合天天-亚日韩久久丫丫私人影院 | 亚洲男人在线 | 无码一区中文字幕人妻 | 国产精品系列在线观看 | 国产一区二区三区久久精品 | 日本高清视频网站www | 亚洲精品亚洲人成在线观看麻豆 | 无码不卡中文字幕一区二区三 | 亚洲乱亚洲乱妇50p 亚洲乱亚洲乱妇无码 | 2025中文字幕乱码免费 | 都市人妻古典武侠另类校园 | 亚洲一区二区在线观看不卡 | 亚洲欧洲国产码专区观看 | 香港aa三级久久三级不卡 | 无码人妻少妇久久中文字幕 | 99久久免费国产精品 | 亚洲一二四区 | 国产一区二区三区四区五区六区 | 蜜臀亚洲av无码精品国产午夜. | a级黑人大硬长爽猛出猛进 a级毛片100部免费观看 | 四虎影视国产精品 | 99久热这里精品免费 | 香蕉久久久久久狠狠色 | 国产精品久久久久久久久久直播 | 国产AV无遮挡喷水喷白浆 | 亚洲国产精品线路久久 | 国产sm调教折磨视频 | 亚州av高清无码在 | 国产精品免费精品自在线观看 | 亚州无线乱码久久 | 国产精品一区二区久久精品 | 国产嫖妓一区二区三区妓女视频 | 久久婷婷丁香五月综合五 | 欧美日韩精品伊人影院在线 | 久久精品国产99国产精品亚洲 | 亚洲无码一区二区在线观看 | 亚洲制服日韩一区二区三区 | 国产在线无码视频一区 | 成人内射国产免费观看 | 亚洲色成人网站www永久四虎 | 国产成人精品免费视频大全软件 |