天天看點

PHPOK企業站新增短信接口

“PHPOK企業站”(簡稱PHPOK)建設系統是一套基于PHP和MySQL建構的高效企業網站建設方案之一,全面針對企業網(以展示為中心)進行合理的設計規劃。這是一套開源的,免費的企業網站程式!二次開發比較簡單,小編對這它還是比較了解的,今天小編就以新增短信接口為例,帶大家進行二次開發。使用的短信接口是短信寶短信群發平台的短信接口,短信寶短信群發平台非常穩定,發送速度快,注冊就送測試短信,推薦大家使用!

我們首先在項目:\gateway\sms 中建立smsbao檔案夾,接着建立sendsms.php檔案,代碼:

<?php
/**
 * 短信寶短信接口
**/
if(!defined("PHPOK_SET")){exit("<h1>Access Denied</h1>");}
$update = $this->get('update');
if($update){
    $mobile = $this->get('mobile');
    if(!$mobile){
        $this->error('未指定手機号');
    }
    if(!$this->lib('common')->tel_check($mobile,'mobile')){
        $this->error('手機号格式不正式');
    }
    $content = $this->get('content');
    if(!$content){
        $this->error('未指定要發送的内容');
    }
 
    if (empty($rs['ext']['smsbao_user']) || empty($rs['ext']['smsbao_pass']) || empty($rs['ext']['smsbao_sign'])) {
        $this->error('請填寫短信寶使用者名、密碼和簽名');
    } 
    
    $url = 'http://api.smsbao.com/sms?u='.$rs['ext']['smsbao_user'].'&p='.md5($rs['ext']['smsbao_pass']).'&m='.$mobile.'&c=【'.$rs['ext']['smsbao_sign'].'】'.$content;
 
    $ret = file_get_contents($url);
    
    if($ret == 0){
        $this->success('短信發送成功');
        return true;
    }
    $this->error($info['message']);
    return false;
}
$this->view($this->dir_root.'gateway/'.$rs['type'].'/sendsms.html','abs-file');
           

然後接着建立exec.php檔案,代碼為:

<?php
 
if(!defined("PHPOK_SET")){exit("<h1>Access Denied</h1>");}
 
 
if (!$rs['ext'] || !$rs['ext']['smsbao_user'] || !$rs['ext']['smsbao_pass'] || !$rs['ext']['smsbao_sign']) {
    if($this->config['debug']){
        phpok_log(P_Lang('短信寶短信參數配置不全'));
    }
    return false;
} 
 
if(!$extinfo['mobile'] || !$extinfo['content']){
    if($this->config['debug']){
        phpok_log(P_Lang('手機号或短信模版未配置'));
    }
    return false;
}
 
$url = 'http://api.smsbao.com/sms?u='.$rs['ext']['smsbao_user'].'&p='.md5($rs['ext']['smsbao_pass']).'&m='.$extinfo['mobile'].'&c=【'.$rs['ext']['smsbao_sign'].'】'.$extinfo['content'];
 
$ret = file_get_contents($url);
 
if ($ret == 0) {
    return true;
} else {
    if($this->config['debug']){
        phpok_log($ret);
    }
    return false;
}
           

最後我們建立一個名為config.xml的檔案,代碼為:

<?xml version="1.0" encoding="utf-8"?>
<root>
    <title>短信寶短信</title>
    <note>官網(http://www.smsbao.com)</note>
    <code>
        <smsbao_user>
            <title>短信寶使用者名</title>
            <note>請輸入您在短信寶注冊的帳号</note>
            <type>text</type>
            <required>true</required>
        </smsbao_user>
        <smsbao_pass>
            <title>短信寶密碼</title>
            <note>請輸入短信寶密碼</note>
            <type>text</type>
            <required>true</required>
        </smsbao_pass>
        <smsbao_sign>
            <title>短信簽名</title>
            <note>請輸入短信簽名</note>
            <type>text</type>
            <required>true</required>
        </smsbao_sign>
        <mobile>
            <title>手機号</title>
            <note>填寫管理者接收短信要用到的手機号,僅支援一個手機号</note>
            <type>text</type>
            <required>true</required>
        </mobile>
    </code>
    <manage>
        <send>
            <title>發短信</title>
            <exec>sendsms</exec>
            <type>page</type>
        </send>
    </manage>
</root>
           

好了,經過以上的替換,短信寶的短信平台已經替換成功了,可以正常使用了。我們可以進行測試發送。

PHPOK企業站新增短信接口

報備一下短信寶的VIP模闆,這樣就可以走短信寶的優質通道了,短信内容3~5秒就可送達。