加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

分享使用tcb-router路由开发的云函数短信平台SDK

发布时间:2020-12-14 19:22:50 所属栏目:资源 来源:网络整理
导读:上篇文章我们分享了如何使用纯的云函数开发的榛子短信短信(http://smsow.zhenzikj.com)SDK,由于微信对于未付费云函数个数的限制,这种方法存在缺陷,经过改进,使用tcb-router作为路由,这样只需要整合到一个云函数中就行 下载sdk和demo:?http://smsow.zhen

上篇文章我们分享了如何使用纯的云函数开发的榛子短信短信(http://smsow.zhenzikj.com)SDK,由于微信对于未付费云函数个数的限制,这种方法存在缺陷,经过改进,使用tcb-router作为路由,这样只需要整合到一个云函数中就行
下载sdk和demo:?http://smsow.zhenzikj.com/sdk...

目前SDK中包含三个功能: send(发送短信)、balance(查询余额)、findSmsByMessageId(查询单条短信)

SDK源码

// 云函数入口文件
const cloud = require('wx-server-sdk')
const TcbRouter = 'tcb-router')
const rq = 'request')
const baseUrl = 'https://smsdeveloper.zhenzikj.com'

cloud.init()

// 云函数入口函数
exports.main = async (event,context) => {
  const app = new TcbRouter({ event });
  
  app.router('send',async (ctx) => {
    ctx.body = new Promise(resolve => {
      rq({
        url: baseUrl + '/sms/send.html',method: "POST",json: true,form: {
          apiUrl: event.apiUrl,appId: event.appId,appSecret: event.appSecret,message: event.message,number: event.number,messageId: event.messageId,}
      },function (error,response,body) {
        resolve({ body: body,error: error })
      });
      // setTimeout(() => {
      //   resolve('male');
      // },500);
    });
  });
  app.router('balance',68);">'/sms/balance.html',appSecret: event.appSecret
        }
      },error: error })
      });
    });
  });
  app.router('findSmsByMessageId',68);">'/sms/findSmsByMessageId.html',messageId: event.messageId
        }
      },error: error })
      });
    });
  });

  return app.serve();
}

如何使用SDK

,data: {
        $url: apiUrl: 'https://sms_developer.zhenzikj.com',appId: '你的appId',appSecret: '你的appSecret',message: '你的验证码为:3333',number: '15822222111',messageId: ''
      }
    }).then((res) => {
      console.log(res.result.body);
    }).catch((e) => {
      //console.log(e);
    });
  },136);">// 查询余额
  balance: function () {
    wx.cloud.callFunction({
      name: '你的appSecret'
      }
    }).then((res) => {
      //console.log(e);
    });
    
    
  },136);">// 查询单条信息
  findSmsByMessageId: function () {
    wx.cloud.callFunction({
      name: 'aaaabbbbba'
      }
    }).then((res) => {
      //console.log(e);
    });

  }
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读