待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

Muucmf_2.0.6新增短信宝短信接口

MuuCmf是一个将CMS和Framework两个概念完美结合的内容管理系统,提供了丰富的系统功能。小编对这款软件还是比较了解的,小编今天就以V2.0.6新增短信接口为例为大家讲解一下如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
1.首先执行以下sql

1
2
3
4
5
6
/**表名前缀根据自身要求进行修改**/
update muucmf_extend_config set extra = 'aliyun:阿里云\r\ntencent:腾讯云\r\nsmsbao:短信宝',value="smsbao" where `group` = "sms" and type="select";
update muucmf_extend_config set value = 'public:公共配置项\r\naliyun_oss:阿里云OSS\r\ntencent_cos:腾讯云COS\r\naliyun_sms:阿里云短信\r\ntencent_sms:腾讯云短信\r\nsmsbao_sms:短信宝\r\nweixinpay:微信支付\r\nalipay:支付宝支付\r\ntencent_vod:腾讯云点播\r\nstore:存储配置\r\nsms:短信配置\r\nvod:点播配置\r\npay:支付配置\r\nwithdraw:提现配置' where `id` = 1;INSERT INTO `muucmf_extend_config` VALUES (99, 'SMS_SMSBAO_USERNAME''string''Username''smsbao_sms''''Username是您访问短信宝的账号,请您妥善保管', 0, 0, 1, '', 0);
INSERT INTO `muucmf_extend_config` VALUES (100, 'SMS_SMSBAO_APIKEY''string''ApiKey''smsbao_sms''''Api Key 是您访问短信宝API的密钥,请您妥善保管', 0, 0, 1, '', 0);
INSERT INTO `muucmf_extend_config` VALUES (101, 'SMS_SMSBAO_SIGN''string''短信签名''smsbao_sms''''应严格按\"【签名名称】\"填写,请参考: https://www.smsbao.com/openapi', 0, 0, 1, '', 0);
INSERT INTO `muucmf_extend_config` VALUES (102, 'SMS_SMSBAO_TEMPLATEID''string''短信模板''smsbao_sms''''您的验证码是{code},30秒内有效.若非本人操作请忽略此消息', 0, 0, 1, '', 0);

2.接着打开后端项目:\app\api\controller\Verify.php文件,在138行添加以下代码

1
2
3
4
5
6
7
8
9
10
// 通过短信宝发送短信
if ($smsDriver == 'smsbao') {
    if (is_array($res) && $res['Code'] == '0') {
        $log_msg "Verify API: Tencent SMS sent successfully - Account: {$account}, Type: {$type}, IP: {$ip}";
        return $this->handleVerifySuccess($account$type$ip$time$log_msg);
    else {
        Log::record("Verify API: SMS sent failed - Account: {$account}, Type: {$type}, IP: {$ip}, Error: {$res['Message']}"'error');
        return $this->error($res['Message']);
    }
}

3.接着打开后端项目:app\common\model\Verify.php文件,在sendSms方法中添加以下代码,

1
2
3
4
5
// 通过短信宝发送短信
if ($smsDriver == 'smsbao') {
   $result $this->smsbao($PhoneNumbers$code);
   return $result;
}

4.接着在后端项目:app\common\model\Verify.php文件中添加短信发送方法

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
40
41
42
43
44
45
46
47
48
/**
     * 通过短信宝发送短信
     */
    public function smsbao($PhoneNumbers$code)
    {
        $user = config('extend.SMS_SMSBAO_USERNAME');
        $apikey = config('extend.SMS_SMSBAO_APIKEY');
        // 短信签名
        $smsSign = config('extend.SMS_SMSBAO_SIGN');
        // 短信模板
        $smsTemplateId = config('extend.SMS_SMSBAO_TEMPLATEID');
        try {
            $TemplateContent str_replace('{code}'$code$smsTemplateId);
            $smsapi "http://api.smsbao.com/";
            $content$smsSign.$TemplateContent;
            $sendurl $smsapi."sms?u=".$user."&p=".$apikey."&m=".$PhoneNumbers."&c=".urlencode($content);
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $sendurl);
            curl_setopt($ch, CURLOPT_TIMEOUT, 1);
            curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $res = curl_exec($ch);
            curl_close($ch);
 
            $statusStr array(
                "0" => "短信发送成功",
                "-1" => "参数不全",
                "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
                "30" => "密码错误",
                "40" => "账号不存在",
                "41" => "余额不足",
                "42" => "帐户已过期",
                "43" => "IP地址限制",
                "50" => "内容含有敏感词",
                "51" => "手机号码不正确"
            );
            $result['Code'] = $res;
            $result['Message'] = $statusStr[$res];
            return $result;
        catch (ClientException $e) {
            // echo $e->getErrorMessage() . PHP_EOL;
            return $e->getErrorMessage() . PHP_EOL;
        catch (ServerException $e) {
            // echo $e->getErrorMessage() . PHP_EOL;
            return $e->getErrorMessage() . PHP_EOL;
        }
    }

5.接着打开前端项目:src\pages\admin\extend\sms.vue文件,在26行添加以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<el-tab-pane label="短信宝" name="smsbao">
                  <div class="cloud-config-content">
                    <el-form :model="formData" label-width="150px" label-position="right">
                      <el-form-item v-for="item in smsbaoConfigList" :key="item.id" :label="item.title">
                        <component
                          :is="getConfigComponent(item.type)"
                          v-model="formData[item.name]"
                          :options="parseOptions(item.extra)"
                          :placeholder="item.remark"
                          :remark="item.remark"
                          :url="item.value"
                        />
                      </el-form-item>
                    </el-form>
                  </div>
                </el-tab-pane>

经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的Muucmf短信宝插件,点击此链接 下载及查看安装流

开源插件

最新更新

电商类

CMS类

微信类

文章标签