调接口发送短信 :用file_get_contents函数,以post方式获取url
来源:互联网 发布:上海php培训哪家好 编辑:程序博客网 时间:2024/05/18 16:37
例:
<?php$data=array('foo'=>'bar');$data=http_build_query($data);$opts=array('http'=>array('method'=>'POST','header'=>"Content-type: application/x-www-form-urlencoded\r\n"."Content-Length: ".strlen($data)."\r\n",'content'=>$data),);$context=stream_context_create($opts);$html=file_get_contents('http://localhost/e/admin/test.html',false,$context);echo$html;?>
应用:post方法调接口
//----------------发送短信--------------------------------//----------------发送短信--------------------------------public function sendMessage($mobile,$message,$teamid){//--2014年12月15日---//email=hrb&Password=0827&MsgContent=您在xxx网站注册的手机验证码为://yvp4vq,此验证码同时也是您的初始登录密码,请在登录后及时修改。//&mobileNumber=18710000000&SendTime=&SubNumber=$sql = "insert into message (contect,sendtime,mobile,teamid) values ('".$message."','".date('Y-m-d H:i:s')."','".$mobile."',".$teamid.")";//var_dump($sql);$query = $this->db->simple_query($sql);if($query){$insID = $this->db->insert_id();date_default_timezone_set('Asia/Chongqing');$data=array('email'=>'XXX', //密码'Password'=>'XXX ', //帐号'MsgContent'=>$message,//'hrb'.date('Y-m-d H:i:s'),'mobileNumber'=>$mobile,'SendTime'=>date('Y-m-d H:i:s'),'SubNumber'=>'',);//echo date('y-m-d h:i:s',time()); $data=http_build_query($data);$opts=array('http'=>array('method'=>'POST','header'=>"Content-type:application/x-www-form-urlencoded\r\n"."Content-Length:".strlen($data)."\r\n",'content'=>$data),);$context=stream_context_create($opts);$html = file_get_contents('http://www.xxxx.com.cn/api/send.asp',false,$context);//http接口地址//echo $html; $result = strpos($html,'<string xmlns="http://tempuri.org/">0');//调用接口时返回的值,右击网页源代码可看到。为这个时代表发送成功//var_dump($result);if($result){$sql = "update message set status = 1 where id = ".$insID;$query = $this->db->simple_query($sql);//echo "短信发送成功!";return TRUE;}else{return FALSE;//echo "短信发送失败!";}}}
转自:http://www.jb51.net/article/20705.htm
另外 :http://bbs.csdn.net/topics/370026897 调用接口 (get方法),
$phonenumber = base64_encode('18999999999');$url = '/interface/11889/getAppListByPhone.php&phonenumber=' . $phonenumber;//发送选项$opts = array('http'=>array('method'=>"GET",'timeout'=>15,));//发送$context = @stream_context_create($opts);$result = @file_get_contents($url,false,$context);$obj = json_decode($result); // 若json_decode($result,TRUE); 则转为数组,下边的判断就为$ojb['status']if(isset($obj) && $obj->status)echo 'OK';elseecho 'FALSE';
// <span style="color:#006600;font-size:16px">json_encode()只将索引数组(indexed array)转为数组格式,而将关联数组(associative array)转为对象格式。</span>
0 0
- 调接口发送短信 :用file_get_contents函数,以post方式获取url
- PHP file_get_contents 函数获取URL的处理
- 以post方式发送链接请求的javascript函数
- file_get_contents 模拟POST数据发送
- httpclient以post方式发送body
- 以Post方式发送数据采用WebClient
- WebClient以POST方式发送Web请求
- 使用post()方法以POST方式从服务器发送数据
- java以URL方式调用接口
- .net 从WebService的restful api接口以POST方式请求并获取返回值
- 以post方式获取远程数据
- Http 以post方式获取数据
- Java 以post方式获取数据
- 微米发送短信Url
- 不用file_get_contents,用curl时。接口调用数据获取
- 向指定URL发送GET或POST请求(调第三方接口)
- ASP.NET以Post方式向网页发送数据
- Java中以POST的方式发送和接收数据
- 【C 实现】返回子串在主串的首位
- Cookie使用和安全
- css中选择器
- dict()的操作方法
- *(leetcode_string) Length of Last Word
- 调接口发送短信 :用file_get_contents函数,以post方式获取url
- CSS魔法堂:盒子模型简介
- QT 线程间QThread的信号和槽
- 安卓 Android SDK 下载 r23.0.2
- 内存分配
- MongoDB学习笔记<四>
- 自定义倒计时控件
- Java遍历Map集合
- cuda QUADRO K600