效果
wxml
<view style="margin-top:22rpx;color:#C5CBED;font-size:30rpx;font-family:'Noto Sans SC';font-weight:normal;">*手机号</view>
<view class="flex">
<input class="padding-left" style="background-color:#F2F8FF;border-radius: 32rpx;width:642rpx;height:42rpx;margin-top:22rpx;color:#DBE1FF;font-size:24rpx;font-family:'Noto Sans SC';font-weight:normal;" bindinput="cellphoneInput" placeholder="该信息栏为必填栏,请真实填写该信息" placeholder-style="color:#DBE1FF;font-family:'Noto Sans SC';font-weight:normal;" type="number" maxlength="11" value="{{cellphone}}" disabled="true"/>
<button class="cu-btn shadow round" style="padding:0;margin-top:22rpx;width:110rpx;background-color: #A5AEDF;color:#fff;height:42rpx;font-size:26rpx;" open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">获取</button>
</view>
js
getPhoneNumber(e){
console.log(e)
console.log(e.detail.code)
var detail = e.detail
var encryptedData = e.detail.encryptedData
var iv = e.detail.iv
var code=e.detail.code
var that = this
wx.request({
url: 'https://api3.qinghansoft.com/api/xl-getPhoneNumber',
data: {
'code':code,
'session_key' : wx.getStorageSync('session_key') ,
'encryptedData' : encryptedData,
'iv' : iv,
},
success(res) {
console.log(res.data);
var response = res.data
var phoneNumber = response['phoneNumber']
console.log(phoneNumber)
that.setData({
'cellphone' : phoneNumber
})
}
})
}
xl-getPhoneNumber API
import logging
import azure.functions as func
import json
import mysql.connector
import datetime
from . import WXBizDataCrypt
import os
import requests
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
appId = 'wx458e8fcf7dc68e24'
sessionKey = req.params.get('session_key')
encryptedData = req.params.get('encryptedData')
iv = req.params.get('iv')
logging.info(encryptedData)
logging.info(iv)
pc = WXBizDataCrypt.WXBizDataCrypt(appId, sessionKey)
logging.info(pc)
result = pc.decrypt(encryptedData, iv)
phoneNumber = result['phoneNumber']
encryptedData = req.params.get('encryptedData')
iv = req.params.get('iv')
response = {
'phoneNumber' : phoneNumber
}
code= req.params.get('code')
appid = 'wx458e8fcf7dc68e24'
appsecret = 'dcb3d5e52d5e71050547c28ec9c97d30'
return func.HttpResponse( json.dumps(response) )