uin-app applet, get mobile phone number

uin-app applet, get mobile phone number

The mini program needs to click a button to obtain a mobile phone number.

The official document code of the native applet is

<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button>

But if this is also the case in uin-app development, the callback function for obtaining the mobile phone number cannot be monitored.
The following code needs to be used.

<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取用户手机号</button>

The event listening code is in methods

<script>
export default {
	methods: {
		data() {
		     return {
		        mobile: '',
		        password: '',
				openid:''
		     };
		},
		getPhoneNumber(e) {
			console.log('获取手机号回调')
			console.log(e)
			console.log(e.detail.iv)
			console.log(e.detail.encryptedData)
		},
	}
 }
	

The data obtained in the getPhoneNumber callback function is encrypted and needs to be decrypted to obtain the mobile phone number. The following is the PHP decryption demo. It should be noted that before obtaining the mobile phone number, you need to call login to obtain the session_key returned by the login.

 public function aesDe($data)
    {
    
    
        $encryptedData = '3ISU/IypKLvNy8kbxwltso7RHVIqbwAKQ4gyWUwRlGTo1Zhyrgl/8ll+fFHbzJOHGnGYZcQV/OgML/LMfEVSqQ==111';
        //encryptedData  getPhoneNumber回调函数中获取
        $key = 'AAs9S3Z0iHmcV5j111NSZRR7g==';
        //登录中 请求https://open.kuaishou.com/oauth2/mp/code2session 返回的 session_key
        $iv = '1bWGrlPSEN7111he1wlwEnZyA==';
         //ivgetPhoneNumber回调函数中获取
        $method = 'AES-128-CBC';
        $encryptedData = $data['encryptedData'];
        $key = base64_decode($key);
        $iv = base64_decode($iv);
        $res =  openssl_decrypt(base64_decode($encryptedData),$method, $key, OPENSSL_RAW_DATA, $iv);
        return json_decode($res,true);
    }

Guess you like

Origin blog.csdn.net/qq_42894991/article/details/123116171