钉钉小程序的免登录

以企业内部应用为例:

	onShow() {
			// 获取免登授权码(这个方法api文档提供)
			dd.getAuthCode({
				success: res => {
					this.authCode = res.authCode
				}
			})
			// 根据appkey和appSecret获取 access_token
			let _this = this
			dd.httpRequest({
				url: 'https://oapi.dingtalk.com/gettoken?appkey=dingppfmbnnby6sf2cbe&appsecret=VOPOaA49nzTKbr1MjFq7FGG-sJh2U2eyFdn3fPe8Jj0JvttEAHMbGmiDddR3S9Bs',
				success: res => {
					_this.access_token = res.data.access_token
					// 根据access_token获取userid
					dd.httpRequest({
						url: 'https://oapi.dingtalk.com/user/getuserinfo?access_token=' + _this.access_token + '&code=' + _this.authCode,
						success: res => {
							_this.userid = res.data.userid
							//获取用户详情
							 dd.httpRequest({
							 	url: 'https://oapi.dingtalk.com/user/get?access_token=' + _this.access_token + '&userid=' + _this.userid,
								success: function(res) {
									console.log("用户详情");
									console.log(res);
							 		console.log(this)
								}
							 })
						},
						fail: function(err) {
							console.log(err)
						}
					})
				},
				fail: function(err) {
					console.log(err)
				}
			})
			

},

你可能感兴趣的:(钉钉小程序)