短信服务

发送短信验证码

接口

POST https://cloud.minapp.com/oserve/v2.1/sms-verification-code/

支持指定短信签名向指定手机号发送短信验证码。

发送短信前请先进行短信签名审核,审核通过后才能发送短信

请求参数

参数类型必填说明
phonestring发送短信验证码的手机
user_idinteger用户 ID (对应 _userprofile 表中的 id 字段)
signature_idinteger发送短信验证码使用的签名 ID,若不指定,将选择最新的过审签名进行发送

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{"phone": "12345678910", "user_id": 66879698, "signature_id": 1}' \
  5. https://cloud.minapp.com/oserve/v2.1/sms-verification-code/
  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v2.1/sms-verification-code/',
  4. method: 'POST',
  5. headers: {
  6. Authorization: `Bearer ${token}`
  7. },
  8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
  9. phone: '12345678910',
  10. signature_id: 1,
  11. user_id: 66879698
  12. }
  13. }
  14. request(opt, function (error, response, body) {
  15. if (error) throw new Error(error);
  16. console.log(response);
  17. });
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v2.1/sms-verification-code/";
  4. $param = array(
  5. "phone" => "12345678910",
  6. "signature_id" => 1,
  7. "user_id" => 66879698
  8. );
  9. $ch = curl_init();
  10. $header = array(
  11. "Authorization: Bearer {$token}",
  12. "Content-Type: application/json; charset=utf-8"
  13. );
  14. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  16. curl_setopt($ch, CURLOPT_URL,$url);
  17. curl_setopt($ch, CURLOPT_POST,true);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($param));
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
  21. $res['response'] = curl_exec($ch); // 反馈结果
  22. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  23. curl_close($ch);

返回示例

  1. {
  2. "status": "ok"
  3. }

状态码说明

200: 成功发送

400: 失败(rate limit 或短信签名没有通过审核)

402: 当前应用已欠费

验证短信验证码

接口

POST https://cloud.minapp.com/oserve/v1.8/sms-verification-code/verify/

请求参数

参数类型必填说明
phonestring需要验证的手机号
codestring收到的验证码
user_idinteger用户 ID (对应 _userprofile 表中的 id 字段)

代码示例

  1. curl -X POST \
  2. -H "Authorization: Bearer cfb5912724dd7ff0b0c17683cc3074bb548bc7f4" \
  3. -H "Content-Type: application/json" \
  4. -d '{"phone": "12345678910", "user_id": 66879698, "code": "352353"}' \
  5. https://cloud.minapp.com/oserve/v1.8/sms-verification-code/verify/
  1. var request = require('request')
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1.8/sms-verification-code/verify/',
  4. method: 'POST',
  5. headers: {
  6. Authorization: `Bearer ${token}`
  7. },
  8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
  9. phone: '12345678910',
  10. code: '352353',
  11. user_id: 66879698
  12. }
  13. }
  14. request(opt, function (error, response, body) {
  15. if (error) throw new Error(error);
  16. console.log(response);
  17. });
  1. <?php
  2. $table_id = 1; // 数据表的 ID
  3. $url = "https://cloud.minapp.com/oserve/v1.8/sms-verification-code/verify/";
  4. $param = array(
  5. "phone" => "12345678910",
  6. "code" => "352353",
  7. "user_id" => 66879698
  8. );
  9. $ch = curl_init();
  10. $header = array(
  11. "Authorization: Bearer {$token}",
  12. "Content-Type: application/json; charset=utf-8"
  13. );
  14. curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
  15. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  16. curl_setopt($ch, CURLOPT_URL,$url);
  17. curl_setopt($ch, CURLOPT_POST,true);
  18. curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($param));
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  20. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,true);
  21. $res['response'] = curl_exec($ch); // 反馈结果
  22. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  23. curl_close($ch);

返回示例

  1. {
  2. "status": "ok"
  3. }

状态码说明

200: 成功发送

400: 验证码错误 / 参数错误