nodejs,阿里云手机号一键登录

const Core = require('@alicloud/pop-core');
const accessKeyId = "xxxx"
const accessSecret = "xxxxO"
var client = new Core({
    accessKeyId: accessKeyId,
    accessKeySecret: accessSecret,
    endpoint: 'https://dypnsapi.aliyuncs.com',
    apiVersion: '2017-05-25'
});
const uuid = ("" + Math.random()).match(/\d{10}/)[0];
//accesstoken:前端通过sdk获取的token,传到后台,后台获取手机号 var params = { "RegionId": "cn-hangzhou", Format: 'JSON', SignatureMethod: 'HMAC-SHA1', SignatureNonce: uuid, SignatureVersion: '1.0', Timestamp: new Date().toISOString(), AccessToken: 'eyJjIjoiTVJ4Ukx1UUdvT0xZc2FwNmMzTzIrUVwvUlBrT01pMWRUNE1zUWZsWVwvN0NIODlqVVwvK09nZTc1UWxlMjBIRXVGZXRvR2FoNHUxdGc4NVxuc01KemptU1FvSUVxT2lpbEt0eXJNMktZV1U3VEpldDZLMEVEOERTMzJaUDV2c0RtQjVyS1wvckZwTWZLcktIVmEzR2ZEUmQraDJGZk5cbnBJYWIwcUYyNmRVTXVQYWxKcVZJMjdMTlVTWXN2UXhUazV2UlcwZHBvMEdsenhpbm8rRFNRZUtaUGNrUXI3QWRhQU9tWFhJdVRkQVFcbmo1YkJsMlFwYkZ2SG93SCttSmpSd2lkTHA5XC9Pc0piWmY2Z3ZUR1daWXEwcTJCRXFcL1lXSGozc2t6Z0gyd3ZmWkRFaG5DcHFXQ3VZRlxuY2JpXC9Na3BibkgyYkd0K3dtQ3BIUDFuUUo3cTg0aEtiUmdhc0o4WkNVbmNLNVpqNkptU1ZDNHRRTjZUQzV1QVRiZFwvNTRRNVl5ZjRmXG5VdU02RDNaT0FoZjRvcVhTRlpCRFwvUFwvaVZiaG5RUkhmYkJoblwvVVV3XC9lY3RCa3hyUk5cL0JybVlua245cU5kb3ZDSHhwWVdOZ1dDXC9iXG5PM2R4bkVwRURJT2g2R01qNVR2VThsVHhUTXIrQ0VcL0ZYelczTHcxaEh1UDd6QlZKR1RZNnpcL0k2RFc5c3lKUU5wejU5Smp6OFFWZnRcbnp0ZkdCMUxRdEpTbCs1NitIVDJmR09XRlRkdHJndFo1b2srODRIOUJMdGRmUGpjMG93eDJnVThJNGNxa0hhaHp1bFNFZ21WMUh5U1ZcblF3NXFGTTRodHFRNFQzZ0FxYitWMGMweXVZVkhZVGc1QVRXWGcwNE56eElaVm8zU3g4K0xzZTF1a3oxVEIreE1sS3d0S2RNeGVIOD1cbiIsImsiOiJZVFA4RUNRczBnZTFGazhTYTBtNkxIdGx5a3hBc082YlJYNGJVYnFvTVVEZXBQdEpaaXBNYW9jYnZCeHJYMDJ6ZExJRzBiYlFuTnNrY3JDTEMwOGZVazBsTk45bUJ5bmxkTnhnZlwvUElyU3ZNYXVPN0pTUVZYT0IzOUNSUVE4Mm9LT3Z6NkZxcHZnMkNjZ0J4Rjl0Szc0WFlCWHFPMEJ2SUR4R05hOVR1d0kwOVVrV1E0MlR3NHYxclloXC9GaE05d1o2WHdGMHhvd2RMY1plUFdIaGVIZ3hlM1RudCtIQjFZWndXZlVUS2U5NzB1VDJwUWNwVkZFNVJ4T0Qzc2gyQ2NQMjdpeUNrTnhBV2VkOTFQWVZUWUdXaFwvM0VYaFwvVWFSSE9NUFYwVDg4ODB2ZUNyWDJubmRsTTRhQXBcL1lxOHA3cmNUUFRCVFhGa2E0bUVWU012Qmc2QT09IiwibyI6IkFuZHJvaWQifQ' } var requestOption = { method: 'POST' }; client.request('GetMobile', params, requestOption).then((result) => { console.log(JSON.stringify(result)); }, (ex) => { console.log(ex); })

  参考文档 前端sdk:https://help.aliyun.com/document_detail/207494.html

      参考文档: 服务端:https://help.aliyun.com/document_detail/26225.html, 注意 签名机制 和  公共参数;

       以上文档为http请求,折腾了一整天没搞定为啥签名错误。最后采用nodejs集成sdk.

      nodejs集成sdk参考:https://api.aliyun.com/#/?product=Dypnsapi&version=2017-05-25&api=GetMobile¶ms={}&tab=DEMO&lang=NODEJS

 

posted @ 2022-02-15 16:36  江山一族  阅读(538)  评论(0编辑  收藏  举报