작은 프로그램 위챗 로그인--

2763 단어 독학 노트
	
	
	
	
	
	

getuserinfo: function (res1) {console.log (res1);/opendid와 비암호화 데이터만 있으면 로그인 완료
			wx.login({
				success: function(res2) {
					console.log(res2);
					// 						//  sessionKey
					wx.request({
						url: 'https:///hoa.hcoder.net/xcxencode/?c=sk&appid=wx59704652556221e6&secret=8e282b8ad3fa81c14cfddb5fa82d7414&code=' +
							res2.code,
						success: function(res3) {
							console.log(res3);
							// 								// 
							try {
								uni.setStorageSync('sk', res3.data.session_key);
								uni.setStorageSync('openid', res3.data.openid);
							} catch (e) {
								//TODO handle the exception
							}
							uni.hideLoading();
							// , 
							// 
							if (!res1.detail.iv) {
								uni.showToast({
									title: " , ",
									icon: "none"
								});
								return false;
							}
							try {
								var sessionKey = uni.getStorageSync('sk');
								console.log(sessionKey);
							} catch (e) {
								//TODO handle the exception
							}
							uni.request({
								/**
								* $appid         = $_POST['appid'];
								 $sessionKey    = $_POST['sessionKey'];
								 $encryptedData = $_POST['encryptedData'];
								 $iv            = $_POST['iv'];
								*/
								method: "POST",
								url: 'https:///hoa.hcoder.net/xcxencode/',
								header: {
									'content-type': 'application/x-www-form-urlencoded'
								},
								data: {
									appid: "wx59704652556221e6",
									sessionKey: sessionKey,
									iv: res1.detail.iv,
									encryptedData: res1.detail.encryptedData
								},
								success: function(res4) {
									//"{"openId":"oS6of0V0rdp9nY_BuvCnQUasOHYc","nickName":" ",
									//"gender":1,"language":"zh_CN","city":"Xi'an","province":"Shaanxi",
									//"country":"China","avatarUrl":"https://wx.qlogo.cn/mmopen/vi_32/7iags6YD4enyU"
									console.log(res4);
									// 
								}
							});
						}
					})
				}
			});
		},
		getuserinfoh5appwx: function() {
			uni.login({
				success: function(rs1) {
					console.log(JSON.stringify(rs1) + '');
					uni.getUserInfo({
						success: function(rs2) {
							console.log(JSON.stringify(rs2) + '2');
						}
					})
				},
			});
		},

좋은 웹페이지 즐겨찾기