OURPHP是一个品牌,一款基于PHP+MySQL开发符合W3C标准的建站系统。是一套非常适用建站者使用的程序,二次开发也比较方便,小编对这款系统还是比较了解的,今天小编就以新增短信接口为例告诉大家如何进行二次开发,我们今天讲解的是1.7.6版本的,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的短信接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们需要在后台添加一个新的API接口,我们进入后台->全局->API接口管理,添加API接口,接口内容为 短信宝短信接口|1|短信宝用户名|短信宝密码 ,修改短信宝用户名和密码为我们自己的,提交。

这样我们就添加好了一个新的API接口,下面我们去写接口文件,打开项目\function\api\telcode\user_regcode.class.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?phpclass ourphpsms{ public function smsconfig($m='',$c='',$s='',$t=1){ global $db; $rs = $db -> select("OP_Key","`ourphp_api`"," where OP_Key LIKE '%短信宝%'"); $rs = explode('|',$rs[0]); if($rs[1] == 2){ return false; }else{ $uid = $rs[2]; $pwd = $rs[3]; $mobile = $m; $mobileids = ''; $content = $c; return $this->sendSMS($http,$uid,$pwd,$mobile,$content,$mobileids,$sign); } } function sendSMS($http,$uid,$pwd,$mobile,$content,$mobileids,$time='',$mid=''){ $data = array ( 'u'=>$uid, //用户账号 'p'=>md5($pwd), //MD5位32密码,密码和用户名拼接字符 'm'=>$mobile, //号码 'c'=>$content, //内容 ); return $this->postSMS($http,$data); //POST方式提交 } function postSMS($url,$data=''){ $port=""; $post=""; $row = parse_url($url); $host = $row['host']; @$port = $row['port'] ? $row['port']:80; $file = $row['path']; while (list($k,$v) = each($data)) { $post .= rawurlencode($k)."=".rawurlencode($v)."&"; //转URL标准码 } $post = substr( $post , 0 , -1 ); $len = strlen($post); $fp = @fsockopen( $host ,$port, $errno, $errstr, 10); if (!$fp) { return "$errstr ($errno)\n"; } else { $receive = ''; $out = "POST $file HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Content-type: application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n"; $out .= "Content-Length: $len\r\n\r\n"; $out .= $post; fwrite($fp, $out); while (!feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("\r\n\r\n",$receive); unset($receive[0]); //return implode("",$receive); return ""; } }}$smskey = new ourphpsms();?> |
好了,经过以上的替换,短信宝的短信平台已经替换成功了,我们去进行发送测试:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。

