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

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

SDK源码

// 云函数入口文件
const cloud = require('wx-server-sdk')
const TcbRouter = require('tcb-router')
const rq = require('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', async (ctx) => {
ctx.body = new Promise(resolve => {
rq({
url: baseUrl + '/sms/balance.html',
method: "POST",
json: true,
form: {
apiUrl: event.apiUrl,
appId: event.appId,
appSecret: event.appSecret
}
}, function (error, response, body) {
resolve({ body: body, error: error })
});
});
});
app.router('findSmsByMessageId', async (ctx) => {
ctx.body = new Promise(resolve => {
rq({
url: baseUrl + '/sms/findSmsByMessageId.html',
method: "POST",
json: true,
form: {
apiUrl: event.apiUrl,
appId: event.appId,
appSecret: event.appSecret,
messageId: event.messageId
}
}, function (error, response, body) {
resolve({ body: body, error: error })
});
});
}); return app.serve();
}

  

如何使用SDK

//index.js
const app = getApp() Page({
data: { }, onLoad: function() { }, // 发送短信
send: function () {
wx.cloud.callFunction({
name: 'zhenzisms',
data: {
$url: 'send',
apiUrl: 'https://sms_developer.zhenzikj.com',
appId: '你的appId',
appSecret: '你的appSecret',
message: '你的验证码为:3333',
number: '15811111111',
messageId: ''
}
}).then((res) => {
console.log(res.result.body);
}).catch((e) => {
//console.log(e);
});
},
// 查询余额
balance: function () {
wx.cloud.callFunction({
name: 'zhenzisms',
data: {
$url: 'balance',
apiUrl: 'https://sms_developer.zhenzikj.com',
appId: '你的appId',
appSecret: '你的appSecret'
}
}).then((res) => {
console.log(res.result.body);
}).catch((e) => {
//console.log(e);
}); },
// 查询单条信息
findSmsByMessageId: function () {
wx.cloud.callFunction({
name: 'zhenzisms',
data: {
$url: 'findSmsByMessageId',
apiUrl: 'https://sms_developer.zhenzikj.com',
appId: '你的appId',
appSecret: '你的appSecret',
messageId: 'aaaabbbbba'
}
}).then((res) => {
console.log(res.result.body);
}).catch((e) => {
//console.log(e);
}); }
})

  

分享使用tcb-router路由开发的云函数短信平台SDK的更多相关文章

  1. [APP] Android 开发笔记 006-使用短信验证SDK进行短信验证

    1. 下载SDK (http://www.mob.com/#/download) SMS For Android Studio: http://www.mob.com/download/sms/and ...

  2. 1、背景介绍及移动云MAS平台 --短信平台

    目的: 刚开发完成一套短信平台以及一个Web端短信发送系统,短信平台耗时两个周.短信发送系统耗时两个多月,开发使用的技术没什么高科技含量,在此主要是记录下很多情况的处理方案,希望能让大家提出改善方案和 ...

  3. 微信小程序开发 -- 通过云函数下载任意文件

    微信小程序开发 -- 通过云函数下载任意文件 1.云开发介绍 ​ 微信小程序开发者众所周知,小程序开发拥有许多限制,当我还是一个菜鸟入门的时候,第一关就卡在了没有备案域名的HTTP请求上面,那时候云开 ...

  4. Luffy之注册认证(容联云通讯短信验证)

    用户的注册认证 前端显示注册页面并调整首页头部和登陆页面的注册按钮的链接. 注册页面Register,主要是通过登录页面进行改成而成. 先构造前端页面 <template> <div ...

  5. ThinkPHP 提供Auth 权限管理、支付宝、微信支付、阿里oss、友盟推送、融云即时通讯、云通讯短信、Email、Excel、PDF 等等

    多功能 THinkPHP 开源框架 项目简介:使用 THinkPHP 开发项目的过程中把一些常用的功能或者第三方 sdk 整合好,开源供亲们参考,如 Auth 权限管理.支付宝.微信支付.阿里oss. ...

  6. Java版阿里云通信短信发送API接口实例(新)

    阿里云通信(原名阿里大于)的短信服务(Short Message Service)是阿里云为用户提供的一种通信服务的能力,支持快速发送短信验证码.短信通知等. 完美支撑双11期间2亿用户,发送6亿短信 ...

  7. android开发学习---开发一个简易的短信发送器

    一.需求: 开发一个简易的短信发送器,输入:对方手机号码,短信内容,点击发送按钮,短信发送成功,对方手机成功收到短信. 其中要求短信内容过长时可以自动拆分,长度英文是160个英文,中文是70个,中英混 ...

  8. zabbix短信(阿里云短信平台)与邮件报警

    环境说明 操作系统 centos7 zabbix_server zabbix 4.0.3 python 3.6.5 短信平台 阿里云短信 zabbix_server配置信息 1 [root@cp-hb ...

  9. html5开发手机打电话发短信功能

    原文:http://www.open-open.com/code/view/1449843459332 在很多的手机网站上,有打电话和发短信的功能,对于这些功能是如何实现的呢.其实不难,今天我们就用h ...

随机推荐

  1. 马拉车算法——边界拓展时加限制hdu4513

    #include<bits/stdc++.h> using namespace std; #define maxn 500005 int n,p[maxn],s[maxn],s_new[m ...

  2. memset函数的实现&printf函数几种输出格式的输出结果

    #include<stdio.h> #include<stdlib.h> void *memmset(void *dest, int ch, int count){ void ...

  3. 写交互式脚本时,遇到到报错:not a regular file

    场景:在写两台ubuntu之间需要交互式登录操作shell脚本.就是在ubantu A上,做点什么事,然后远程到ubuntu B上进行操作,shell脚本存放在ubuntu A上. 我遇到这个报错:n ...

  4. vapor 生成xcode project 产生的错误解决方式

    运行vapor xcode时报错: Could not generate Xcode project: error: terminated(72): xcrun --sdk macosx --find ...

  5. .net core ef 通过dbfirst方式连接mysql数据库

    1. 创建基于.net core的项目(过程略) 2. 利用nuget添加以下引用 MySql.Data.EntityFrameworkCore         Pomelo.EntityFramew ...

  6. Semantic difference between object expressions and declarations

    object expressions are executed (and initialized) immediately, where they are used; object declarati ...

  7. Linux下crontab计划任务使用详解

    Linux在相应用户下,用crontab -l 命令可以查看该用户定时执行的任务,-e可以编辑,但是其真实文件在哪儿呢??以CentOS为例,其真实的位置在:/var/spool/cron下面,有执行 ...

  8. SDK踩坑全纪录

    No1: Unity2017.1版本导出的android工程放到Android Studio上跑起来非常卡,Unity2017.3或4版本导出就没问题. 对比后发现gradle文件有差异,特此标注 1 ...

  9. [Log函数]C++log函数使用

    先引入头文件#include<cmath> 以e为底:log(exp(n)) 以10为底:log10(n) 以m为底:log(n)/log(m)

  10. 福州大学软件工程1916|W班 第3次作业成绩排名

    作业链接 结对第二次-文献摘要热词统计及进阶需求 评分细则 本次作业由三部分组成(程序满分80,博客满分70,工程能力满分30) 程序评分标准 基础需求 共有7个测试用例,每个满分20分并按照一定的映 ...