func-aliyun-sms.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const sms = require("ali-sms");
  2. const SMSAccessKeyID = process.env.ALI_SMS_ACCESSKEYID || "LTAI5tETwA37KgHfDo5p2Ej6";
  3. const SMSAccessKeySecret = process.env.ALI_SMS_ACCESSKEYSECRET || "EBDQEchETlNcEYzE8zYb1zl4gBImrJ";
  4. /**
  5. * @desc
  6. curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' http://8.140.98.43/parse/functions/aliSmsSend
  7. curl -X POST -H "Content-Type: application/json" -H 'X-Parse-Application-Id: edu-textbook' -d '{ "mobileList": ["18607007073"],"templateCode":"SMS_468995773","params":{},"signName":"普通高等教育教材网" }' http://127.0.0.1:61337/parse/functions/aliSmsSend
  8. * @returns
  9. 成功
  10. {"result":"{\"Message\":\"OK\",\"RequestId\":\"41DDC6F4-A8B8-55A3-95E7-AD06D3F0E94F\",\"Code\":\"OK\",\"BizId\":\"261804722010619993^0\"}"}
  11. 失败
  12. {"result":"{\"Message\":\"手机号码格式错误\",\"RequestId\":\"63C4A4DB-B337-5630-8E00-51535C7377D7\",\"Code\":\"isv.MOBILE_NUMBER_ILLEGAL\"}"}
  13. */
  14. export function defineAliSMSSend(){
  15. // function defineAuthingLogin(){
  16. Parse.Cloud.define("aliSmsSend", async (request) => {
  17. let mobileList = request.params.mobileList;
  18. let signName = request.params.signName;
  19. let params = request.params.params;
  20. let templateCode = request.params.templateCode;
  21. let result = await sendAliyunSMS({
  22. signName:signName,
  23. mobileList:mobileList,
  24. params:params,
  25. templateCode:templateCode
  26. })
  27. return result
  28. },{
  29. fields : {
  30. mobileList:{
  31. required:true
  32. },
  33. params:{
  34. required:true
  35. },
  36. signName:{
  37. required:true
  38. },
  39. templateCode:{
  40. required:true
  41. },
  42. }
  43. });
  44. }
  45. /**
  46. * @desc
  47. 手机号解绑验证码 SMS_469065757
  48. 手机号修改验证码 SMS_469055726
  49. 手机号绑定验证码 SMS_468890757
  50. 密码重置验证码 SMS_468915747
  51. 账号认证失败通知 SMS_468995773
  52. 账号认证成功通知 SMS_468870790
  53. 账号注册通知 SMS_469060724
  54. */
  55. async function sendAliyunSMS(options){
  56. return new Promise(resolve=>{
  57. const config = {
  58. accessKeyID : SMSAccessKeyID,
  59. accessKeySecret : SMSAccessKeySecret,
  60. paramString : options?.params,
  61. recNum : options?.mobileList,
  62. signName : options?.signName,
  63. templateCode : options?.templateCode,
  64. };
  65. sms(config, (err, body) => {
  66. console.log(err, body);
  67. resolve(body||err)
  68. });
  69. })
  70. }
  71. module.exports.sendAliyunSMS = sendAliyunSMS()