小程序 根据code获取手机号
This commit is contained in:
parent
6ecf53dcf6
commit
dca0397198
|
|
@ -26,4 +26,13 @@ export declare class WechatMpInstance {
|
|||
};
|
||||
isHyaline?: true;
|
||||
}): Promise<ArrayBuffer>;
|
||||
getUserPhoneNumber(code: string): Promise<{
|
||||
phoneNumber: string;
|
||||
purePhoneNumber: string;
|
||||
countryCode: number;
|
||||
watermark: {
|
||||
timestamp: number;
|
||||
appid: string;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -157,6 +157,30 @@ var WechatMpInstance = /** @class */ (function () {
|
|||
});
|
||||
});
|
||||
};
|
||||
WechatMpInstance.prototype.getUserPhoneNumber = function (code) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
var token, result;
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.getAccessToken()];
|
||||
case 1:
|
||||
token = _a.sent();
|
||||
return [4 /*yield*/, this.access("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=".concat(token), {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
code: code,
|
||||
}),
|
||||
})];
|
||||
case 2:
|
||||
result = (_a.sent());
|
||||
return [2 /*return*/, result.phone_info];
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
return WechatMpInstance;
|
||||
}());
|
||||
exports.WechatMpInstance = WechatMpInstance;
|
||||
|
|
|
|||
|
|
@ -156,4 +156,33 @@ export class WechatMpInstance {
|
|||
);
|
||||
return (await result.arrayBuffer()) as ArrayBuffer;
|
||||
}
|
||||
|
||||
async getUserPhoneNumber(code: string) {
|
||||
const token = await this.getAccessToken();
|
||||
const result = (await this.access(
|
||||
`https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=${token}`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
code,
|
||||
}),
|
||||
}
|
||||
)) as {
|
||||
errcode: number;
|
||||
errmsg: 'ok' | string;
|
||||
phone_info: {
|
||||
phoneNumber: string;
|
||||
purePhoneNumber: string;
|
||||
countryCode: number;
|
||||
watermark: {
|
||||
timestamp: number;
|
||||
appid: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
return result.phone_info;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue