使用物联网卡发送短信

                    <p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">从2015年9月1日起 ,购买电话卡需要实名制,也就是说需要本人使用身份证才能购买。但是随着物联网的迅速发展,需要联网的终端逐渐增多。在此环境下,诞生了一种不能电话,不能短信,不需要实名制,只能上网的物联网卡。但是在某些场合,需要用到短信功能。本教程使用合宙的API发送短信,一条短信只需要4分钱。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">1、购买短信</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">注册<a href="http://sms.openluat.com/" rel="nofollow" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">短信中心</a>账号,并登陆。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">进入账户管理->充值, 选择您要购买短信的规格,付款</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="https://img-blog.csdn.net/20180802083522242?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2E5MDkyMDQwMTM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70" alt="这里写图片描述" title="" style="outline: 0px; border-style: none; margin: 24px 0px; max-width: 100%; word-break: break-all; cursor: zoom-in;"> <br style="outline: 0px; word-break: break-all;">2、新建签名</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">进入签名管理->签名管理->新建, 签名创建完成之后,在签名管理页面查看签名状态,<span style="outline: 0px; font-weight: 700; word-break: break-all;">签名审核通过之后就可以用来发送短信。</span></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-qJbOnsVi5b9c7706ce421.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 565.6px;"></p><div><br></div><ul style="outline: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">发送短信之前,客户首先需要在公司平台对签名进行备案,备案时需要提供签名的文本。</p></li><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">提交的短信签名 2-10 个字符; 建议全用中文。</p></li><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">其中“梅云飞”就是签名,<span style="outline: 0px; font-weight: 700; word-break: break-all;">如果没有签名就不能发送短信 </span>。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-RfsCjBO15b9c7777c63a7.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 373.5px;"></p></li><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><div>审核时间为工作日的9点至17点</div></li></ul><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">3、新建模版</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">进入签名管理->模版管理->新建, 模版创建成功之后,在模版管理页面查看模版状态,模版审核通过之后就可以用来发送短信, <span style="outline: 0px; font-weight: 700; word-break: break-all;">如果没有通过的模版就不能发送短信</span></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-jCl2JiFO5b9c77e171ea4.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 565.6px;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">注:</p><ul style="outline: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">发送新短信内容之前,客户首先需要在我公司平台对模板进行备案,备案时需要提供模板的文本。后面发送已通过模版的内容就不用申请模版了。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">提交报备模板规范: <br style="outline: 0px; word-break: break-all;">提交短信模板的内容规则,例 <br style="outline: 0px; word-break: break-all;">例 1:您的验证码是????,请在 5 分钟内使用。 <br style="outline: 0px; word-break: break-all;">例 2:%先生,欢迎您光临%店铺,祝您购物愉快。 <br style="outline: 0px; word-break: break-all;">? 和 % 表示通配符,?匹配 1 个字符,%匹配 N 个字符。 <br style="outline: 0px; word-break: break-all;">说明: <br style="outline: 0px; word-break: break-all;">其中N匹配0到多个字符 <br style="outline: 0px; word-break: break-all;">发送提交短信的内容: <br style="outline: 0px; word-break: break-all;">通过短信发送页面发送短信,短信的内容规则为: <br style="outline: 0px; word-break: break-all;">例:您的验证码是 1234,请在 5 分钟内使用。</p></li></ul><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">4、创建应用</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">进入应用管理->创建应用,填写您要创建的应用名称,应用描述,然后创建。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-VFMM0j7z5b9c77fa942c4.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 50%;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">创建应用成功后在应用管理->应用列表里面查看自己的应用,应用的appkey,appsecret用于下面API接口的调用</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">至此,可以通过短信平台发送短信了。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-u1oHrjPW5b9c781a28314.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 524px;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><br></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">可以在发送记录中查看发送状态 <br style="outline: 0px; word-break: break-all;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-MS3cPRaR5b9c783370901.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 311px;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">除了使用短信平台发送短信,还可以使用API发送短信。</p><h1 id="短信api" style="outline: 0px; padding: 0px; margin-top: 8px; margin-bottom: 16px; font-size: 28px; color: rgb(79, 79, 79); font-weight: 700; line-height: 36px; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">短信API</h1><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><span style="outline: 0px; font-weight: 700; word-break: break-all;">请求URL :</span></p><ul style="outline: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;"><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;"><code style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; border-radius: 2px; word-break: break-all;">api.openluat.com/sms/send</code></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all;">请求方式:POST</p></li></ul><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><span style="outline: 0px; font-weight: 700; word-break: break-all;">认证:</span></p><ul style="outline: 0px; margin-right: 0px; margin-bottom: 24px; margin-left: 0px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;">在headers中增加Basic auth的认证,填入(appkey, appsecret)</li><li style="outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; word-break: break-all;">认证方式为HTTP Basic Authorization,认证信息为appkey:appsecret,详细调用请参考各个语言的HTTP Basic Authorization</li></ul><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">以下补充关于Basic Authorization相关知识:</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">在HTTP中,<span style="outline: 0px; font-weight: 700; word-break: break-all;">基本认证</span>(Basic access authentication)是一种用来允许网页浏览器或其他客户端程序在请求时提供用户名和口令形式的身份凭证的一种登录验证方式。</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">在发送之前是以用户名追加一个冒号然后串接上口令,并将得出的结果字符串再用Base64算法编码。例如,提供的用户名是<code style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; border-radius: 2px; word-break: break-all;">Aladdin</code>、口令是<code style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; border-radius: 2px; word-break: break-all;">open sesame</code>,则拼接后的结果就是<code style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; border-radius: 2px; word-break: break-all;">Aladdin:open sesame</code>,然后再将其用Base64编码,得到<code style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; line-height: 22px; border-radius: 2px; word-break: break-all;">QWxhZGRpbjpvcGVuIHNlc2FtZQ==</code>。最终将Base64编码的字符串发送出去,由接收者解码得到一个由冒号分隔的用户名和口令的字符串。(摘自维基百科)</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;">服务器将Authorization header中的用户名密码取出,进行验证, 如果验证通过,将根据请求,发送资源给客户端</p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><img src="http://oldask.openluat.com/image/show/attachments-2018-09-Jmo6JnTo5b9c784a579d7.png" class="img-responsive" style="color: rgb(0, 0, 0); font-family: "Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "WenQuanYi Micro Hei", "Microsoft Yahei", sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 611px;"></p><div><br></div><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><a href="https://www.cnblogs.com/chenrong/articles/5818498.html" rel="nofollow" target="_blank" style="outline: 0px; color: rgb(103, 149, 181); cursor: pointer; word-break: break-all;">http authorization 基本认证</a></p><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><span style="outline: 0px; font-weight: 700; word-break: break-all;">参数:</span></p><table style="outline: 0px; background-color: rgb(255, 255, 255); width: 852px; text-align: center; margin-bottom: 24px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><thead style="outline: 0px; word-break: break-all;"><tr style="outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;"><th align="left" style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle; background-color: rgb(239, 243, 245);">参数名</th><th style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle; background-color: rgb(239, 243, 245);">必选</th><th style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle; background-color: rgb(239, 243, 245);">类型</th><th style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle; background-color: rgb(239, 243, 245);">说明</th></tr></thead><tbody style="outline: 0px; border: 0px; word-break: break-all;"><tr style="outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;"><td align="left" style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">content</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">是</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">string</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">短信内容</td></tr><tr style="outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); background-color: rgb(247, 247, 247); word-break: break-all;"><td align="left" style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">phone</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">是</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">string</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">被叫号码,多个被叫号码用英文的逗号分隔,最多支持 100 个被叫号码。</td></tr><tr style="outline: 0px; border-width: 1px 0px 0px; border-right-style: initial; border-bottom-style: initial; border-left-style: initial; border-right-color: initial; border-bottom-color: initial; border-left-color: initial; border-image: initial; border-top-style: solid; border-top-color: rgb(221, 221, 221); word-break: break-all;"><td align="left" style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">sign</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">是</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">string</td><td style="outline: 0px; padding: 8px; margin: 0px; border: 1px solid rgb(221, 221, 221); word-break: normal; color: rgb(79, 79, 79); line-height: 22px; word-wrap: break-word; vertical-align: middle;">签名</td></tr></tbody></table><p style="outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, "SF UI Text", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif; font-variant-ligatures: common-ligatures;"><span style="outline: 0px; font-weight: 700; word-break: break-all;">返回示例</span></p><pre class="prettyprint" name="code" style="outline: 0px; padding: 8px 16px 6px 56px; margin-bottom: 24px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; position: relative; overflow-y: hidden; line-height: 22px; color: rgb(0, 0, 0); background-color: rgb(246, 248, 250); border-width: initial; border-style: none; border-color: initial; font-variant-ligatures: common-ligatures;"><code class="language-lua hljs  has-numbering" style="outline: 0px; font-family: Consolas, Inconsolata, Courier, monospace; font-size: 14px; display: block; padding: 0.5em; color: rgb(0, 0, 0); line-height: 22px; background-color: rgb(246, 248, 250); border-radius: 4px; overflow-x: auto; white-space: pre; word-wrap: normal; text-size-adjust: none; word-break: break-all;"> {
<span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"code"</span>: <span class="hljs-number" style="outline: 0px; color: rgb(0, 102, 102); font-size: inherit; word-break: break-all;">0</span>,
<span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"msg"</span>: <span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">''</span>,
<span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">"msgid"</span>:<span class="hljs-string" style="outline: 0px; color: rgb(0, 153, 0); font-size: inherit; word-break: break-all;">'592FAC0300000D70'</span>

}

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>返回参数说明:

<table style=”outline: 0px; background-color: rgb(255, 255, 255); width: 852px; text-align: center; margin-bottom: 24px; word-break: break-all; color: rgba(0, 0, 0, 0.75); font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>参数名类型说明codeint状态码,0:成功;1:失败msgstring错误提示: code为1时才有msgidstring消息id:用于匹配回调中的 msgid<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>下面提供几个实际操作示例

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>python

import requests
from requests.auth import HTTPBasicAuth
url = 'https://api.openluat.com/sms/send'
payload = {
'content': '您的验证码是1234,请在5分钟内使用。',
'phone': '手机号',
'sign': '签名', #sign是在 http://sms.openluat.com/temp 创建的
}
appkey = 'appkey'
appsecret = 'appsecret'
#appkey,appsecret是在 http://sms.openluat.com/establish 创建的
#在 http://sms.openluat.com/establog 查看自己的appkey,appsecret。
auth = HTTPBasicAuth(appkey, appsecret)
r = requests.post(url, data=payload, auth=auth)
print(r.json())
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>以下示例使用Air202模块,Air202模块可以同时采用Lua语言进行二次开发和AT命令开发。

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>luat

module(...,package.seeall)

require“http”

–HTTP发送后的回调函数
local function cbFnc(result,prompt,head,body)
log.info(“testHttp.cbFnc”,result,prompt)
if result and head then
for k,v in pairs(head) do
log.info(“testHttp.cbFnc”,k..“: “..v)
end
end
if result and body then
log.info(“testHttp.cbFnc”,“bodyLen=”..body:len())
end
end

http.request(“POST”,“appkey:appsecret@api.openluat.com/sms/send”,
nil,{[‘Content-Type’]=“application/x-www-form-urlencoded”},“content=您的验证码为:882474,请尽快确认!&phone=18680841753&sign=测试使用”,nil,cbFnc)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>从trace输出看到已经发送成功

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”><img src=”http://oldask.openluat.com/image/show/attachments-2018-09-WMd2yTia5b9c7865498d0.png" class=”img-responsive” style=”color: rgb(0, 0, 0); font-family: “Helvetica Neue”, Helvetica, Arial, “PingFang SC”, “Hiragino Sans GB”, “WenQuanYi Micro Hei”, “Microsoft Yahei”, sans-serif; font-size: 14px; font-variant-ligatures: normal; text-align: start; width: 625px;”>


<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>AT

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>使用AT命令也可以通过调用API发送短信

->  AT+SAPBR=3,1,"CONTYPE","GPRS" #设置HTTP功能的承载类型SAPBR是为了激活PDP上下文,激活PDP上下位是为了使用UDP协议,从而可以解析域名。
<- OK
-> AT+SAPBR=3,1,"APN","CMNET" #设置HTTP功能的APN
<- OK
-> AT+SAPBR=5,1 #保存cid=1的承载的相关参数(CONTYPE,APN)到NV,这样关机不消失,并且开机后自动恢复为保存的取值。
<- OK
-> AT+SAPBR=1,1 #激活该承载的GPRSPDP上下文
<- OK
-> AT+SAPBR=2,1 #查询下承载的状态
<- OK
<- +SAPBR: 1,1,"10.153.61.216" #第一个参数1表示cid,第二个参数1表示已经连接,第三个参数表示模块获取的IP地址
-> AT+HTTPINIT #HTTP协议栈初始化
<- OK
-> AT+HTTPPARA="CID",1 #设置HTTP会话参数:CID
<- OK
-> AT+HTTPPARA="URL","api.openluat.com/sms/send" #设置HTTP会话参数:URL
<- OK
-> AT+HTTPPARA="USER_DEFINED","Content-Type: application/x-www-form-urlencoded" #设置自定义参数
<- OK
-> AT+HTTPPARA="USER_DEFINED","Authorization: Basic appsecret:appsecret base64编码后的数据" #设置auth认证
<- OK

-> AT+HTTPDATA=191,100000 #191为post内容的长度,输入时间要设定的足够大以保证数据输入
DOWNLOAD #出现download开始输入post内容
content=%E6%82%A8%E7%9A%84%E9%AA%8C%E8%AF%81%E7%A0%81%E4%B8%BA123456%EF%BC%8C%E8%AF%B7%E5%B0%BD%E5%BF%AB%E7%A1%AE%E8%AE%A4%EF%BC%81&phone=18680841753&sign=%E6%B5%8B%E8%AF%95%E4%BD%BF%E7%94%A8
<- OK
-> AT+HTTPACTION=1 #POST开始
<- OK

+HTTPACTION: 1,200,62 #POST结束
-> AT+HTTPREAD #读取返回内容
<- +HTTPREAD: 62
{
“code”: 0,
“msg”: “”,
“msgid”: “5B5809F9000022C7”
}

OK

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>可以看到已经成功发送出去。需要注意的是post的内容需要对中文进行utf-8的url编码 

<p style=”outline: 0px; padding: 0px; margin-bottom: 16px; font-size: 16px; color: rgb(79, 79, 79); line-height: 26px; text-align: justify; word-break: break-all; font-family: -apple-system, “SF UI Text”, Arial, “PingFang SC”, “Hiragino Sans GB”, “Microsoft YaHei”, “WenQuanYi Micro Hei”, sans-serif; font-variant-ligatures: common-ligatures;”>从上面Luat和AT的例子可以看出,在完成较复杂逻辑的时候,Luat明显优于AT命令。

上次更新 2021-01-28