小程序 获取手机号 server逻辑待实现
This commit is contained in:
parent
d95164a323
commit
cbf0decf74
|
|
@ -6,6 +6,7 @@ import {
|
|||
sendCaptcha,
|
||||
switchTo,
|
||||
refreshWechatPublicUserInfo,
|
||||
getWechatMpUserPhoneNumber,
|
||||
} from './token';
|
||||
import { getUploadInfo } from './extraFile';
|
||||
import { getApplication } from './application';
|
||||
|
|
@ -25,4 +26,5 @@ export const aspectDict = {
|
|||
getApplication,
|
||||
updateConfig,
|
||||
updateApplicationConfig,
|
||||
getWechatMpUserPhoneNumber,
|
||||
};
|
||||
|
|
@ -1349,4 +1349,27 @@ export async function switchTo<ED extends EntityDict, Cxt extends BackendRuntime
|
|||
id: token.id,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
|
||||
export async function getWechatMpUserPhoneNumber<
|
||||
ED extends EntityDict,
|
||||
Cxt extends BackendRuntimeContext<ED>
|
||||
>({ code }: { code: string }, context: Cxt) {
|
||||
const application = context.getApplication();
|
||||
const { type, config, systemId } = application!;
|
||||
assert(type === 'wechatMp' && config!.type === 'wechatMp');
|
||||
const config2 = config as WechatMpConfig;
|
||||
const { appId, appSecret } = config2;
|
||||
const wechatInstance = WechatSDK.getInstance(
|
||||
appId,
|
||||
appSecret,
|
||||
'wechatMp'
|
||||
) as WechatMpInstance;
|
||||
const result = await wechatInstance.getUserPhoneNumber(code);
|
||||
//获取 没区号的手机号码
|
||||
const purePhoneNumber = result?.purePhoneNumber;
|
||||
//todo 需要干什么
|
||||
|
||||
return '授权成功'
|
||||
|
||||
}
|
||||
|
|
@ -197,7 +197,12 @@ export class Token<
|
|||
}
|
||||
|
||||
async refreshWechatPublicUserInfo() {
|
||||
await this.cache.exec('refreshWechatPublicUserInfo', {});
|
||||
this.publish();
|
||||
await this.cache.exec('refreshWechatPublicUserInfo', {});
|
||||
this.publish();
|
||||
}
|
||||
|
||||
async getWechatMpUserPhoneNumber() {
|
||||
await this.cache.exec('getWechatMpUserPhoneNumber', {});
|
||||
this.publish();
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,9 @@ export default OakComponent({
|
|||
},
|
||||
data: {
|
||||
mobile: '',
|
||||
password: '',
|
||||
captcha: '',
|
||||
counter: 0,
|
||||
refreshing: false,
|
||||
},
|
||||
properties: {
|
||||
onlyCaptcha: Boolean,
|
||||
|
|
@ -91,5 +91,27 @@ export default OakComponent({
|
|||
});
|
||||
}
|
||||
},
|
||||
async onRefreshMobile(e: any) {
|
||||
this.setState({
|
||||
refreshing: true,
|
||||
});
|
||||
try {
|
||||
const { code, errMsg } = e.detail;
|
||||
if (errMsg !== 'getPhoneNumber:ok') {
|
||||
console.error(errMsg);
|
||||
this.setMessage({
|
||||
title: '获取手机号失败',
|
||||
type: 'warning',
|
||||
});
|
||||
} else {
|
||||
await this.features.token.getWechatMpUserPhoneNumber(code);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
this.setState({
|
||||
refreshing: false,
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import assert from "assert";
|
||||
|
||||
export default OakComponent({
|
||||
entity: 'mobile',
|
||||
|
|
@ -57,8 +56,7 @@ export default OakComponent({
|
|||
type: 'warning',
|
||||
});
|
||||
} else {
|
||||
assert(code);
|
||||
console.log(code);
|
||||
await this.features.token.getWechatMpUserPhoneNumber(code);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
|
|
|||
Loading…
Reference in New Issue