hnxylc8818@163.com
hnxylc8818@163.com
  • 发布:2020-06-09 18:21
  • 更新:2020-06-10 14:22
  • 阅读:529

uniCloud 云函数里调用阿里云发送短信服务失败

分类:uniCloud

'use strict';  

async function sendSms(event, context) {  
    //event为客户端上传的参数  
    console.log('event : ' + event)       
    // now just use the cache  

    // ACCESS_KEY_ID/ACCESS_KEY_SECRET 根据实际申请的账号信息进行替换  
    const accessKeyId = 'xxx'  
    const secretAccessKey = 'xxx'  

    const Core = require('@alicloud/pop-core');  

    var client = new Core({  
      accessKeyId,  
      secretAccessKey,  
      endpoint: 'https://dysmsapi.aliyuncs.com',  
      apiVersion: '2017-05-25'  
    });  

    let code = generateCode();  

    var params = {  
      "PhoneNumbers": "xxxx",  
      "SignName": "xx",  
      "TemplateCode": "xxxx",  
      "TemplateParam": "{'code':'123456'}"  
    }  

    var requestOption = {  
      method: 'POST'  
    };  

    client.request('SendSms', params, requestOption).then((result) => {  
      console.log("result:"+JSON.stringify(result));  
    }, (ex) => {  
      console.log("ex:" + ex);  
    })  

    //返回数据  
    return code  
}  

function generateCode() {  
    var code = "";  
    for (var i = 0; i < 6; i++) {  
        code += Math.floor(Math.random() * 10);  
    }  
    return code;  
}  

exports.main = sendSms
2020-06-09 18:21 负责人:无 分享
已邀请:
DCloud_UNI_WYQ

DCloud_UNI_WYQ

client.request('SendSms', params, requestOption).then((result) => {    
      console.log("result:"+JSON.stringify(result));    
    }, (ex) => {    
      console.log("ex:" + ex);    
    })  

这块换成await试试看是什么样的

DCloud_UNI_WYQ

DCloud_UNI_WYQ

  • hnxylc8818@163.com (作者)

    客户端是微信小程序,安全域名都添加过了

    2020-06-10 11:21

hnxylc8818@163.com

hnxylc8818@163.com (作者)

客户端是微信小程序,安全域名都添加过了

要回复问题请先登录注册