Home  >  Article  >  Backend Development  >  php短信发送函数——php短信接口制造的短信发送函数

php短信发送函数——php短信接口制造的短信发送函数

WBOY
WBOYOriginal
2016-06-13 11:00:49852browse

php短信发送函数——php短信接口制作的短信发送函数
作者:zccst
版本一:
有时大家在作php 集成时,经常在网页中用到发送短信的情况,那么可以将短信发送作成一个函数来处理,这样方便以后调用。

如可将函数定义在Function.php中,代码如下:

function smsto($telphone,$message){//短信接口用户名 $uid,如果没有或不能发送请与客服QQ:272927682联系$uid = 'qxt01';//短信接口密码 $passwd$passwd = '123456';//发送到的目标手机号码 $telphone//$telphone = '13845689748';//此处改成自己的手机号//短信内容 $message//$message = "这是一条测试信息";$message1 =urlencode(mb_convert_encoding($message, 'utf-8', 'gb2312'));$gateway = "http://sms.zgqxt.com/msgsend.ashx?USERNAME={$uid}&PASSWORD={$passwd}&MOBILE={$telphone}&CONTENT={$message1}&SEQ=1000";$result = file_get_contents($gateway);      return $result;}

然后在相关的页面中实现发送,并返回发送结果 如下
    $SendMember = $_POST["SendMember"];  //说明:取用户输入的手号,也可以自己指定手机号    $SendMSG  = $_POST["SendMSG"];//说明:取用户输入的短信内容,也可以自己指定内容    $smsok=smsto($SendMember,$SendMSG);


返回1说明成功,更多返回值请查看接口说明。



版本二:
第一步:先到www.woxp.cn注册一个会员账号;

第二步:在test.php文件中插入代码:
<?php$cont="你好,这是我发的测试短信,祝你成功!";$mynum="手机号码";$url='http://gateway.woxp.cn:6630/gb2312/web_api/?x_eid=0&x_uid=会员账号&x_pwd_md5=MD5加密后的密码&x_ac=10&x_target_no='."$mynum".'&x_memo='."$cont".'&x_gate_id=300';echo Get($url);function Get($url){    if(function_exists('file_get_contents')){      $file_contents = file_get_contents($url);    }else{      $ch = curl_init();      $timeout = 5;      curl_setopt ($ch, CURLOPT_URL, $url);      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);      curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);      $file_contents = curl_exec($ch);      curl_close($ch);    }    return $file_contents;}?>



第三步,浏览test.php,如果参数配置正确,则短信可成功到达预设手机号码上,完毕!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php中双冒号的施用Next article:PHP中的java形式重载