php fsockopen例子
<?php
/*
* 短信相关api
*/
class Webcall {
protected $VCC_CODE; //api的账号
protected $password; //api的密码
protected $api_url; //api的地址
/*
* 设置api相关参数
* */
public function __construct() {
$this->CI = & get_instance();
$this->CI->config->load('config.php');
$sms_config = $this->CI->config->item('callcenter');
$this->api_url = $sms_config['api_url'];
$this->VCC_CODE = $sms_config['vcc_code'];
$this->secret = $sms_config['secret'];
}
/*
* 请求打电话接口
* @param array $param 要发送的参数
* */
public function post_api($param = array()) {
$url_info = parse_url($this->api_url);
$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
$httpheader .= "Host:" . $url_info['host'] . "\r\n";
$httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n";
$httpheader .= "Content-Length:" . strlen(http_build_query($param)) . "\r\n";
$httpheader .=$this->get_auth();
$httpheader .= "Connection:close\r\n\r\n";
$httpheader .= http_build_query($param);
$fd = fsockopen($url_info['host'], 80);
fwrite($fd, $httpheader);
$gets = "";
while(!feof($fd)) {
$gets .= fread($fd, 128);
}
fclose($fd);
return $gets;
}
/**
* 生成调用电话接口的验证数据
* @param none
* */
public function get_auth() {
$nonce = rand(100000, 999999); //base64_encode('žY');//$this->CI->security->get_random_bytes(5));
$time = time();
$PasswordDigest = base64_encode(sha1(base64_decode($nonce) . $time . $this->secret, true));
$header = "X-WSSE:UsernameToken Username=\"" . $this->VCC_CODE . "\",PasswordDigest=\"" . $PasswordDigest . "\",Nonce=\"" . $nonce . "\",Created=\"" . $time . "\"\r\n";
return $header;
}
/**
* 医生打电话给用户
* @param string $caller 先接通一方号码
* @param string $called 后接通一方号码
* */
public function call($caller, $called) {
$params = array('vcc_code' => $this->VCC_CODE, 'caller' => $caller, 'called' => $called, 'display_caller' => '59222733', 'display_called' => '59222733');
$res = $this->post_api($params);
if (strpos($res, 'ok') !== FALSE) {
return TRUE;
}
return FALSE;
}
}
php fsockopen例子的更多相关文章
- PHP模拟发送POST请求之三、用Telnet和fsockopen()模拟发送POST信息
了解完了HTTP头信息和URL信息的具体内容,我们开始尝试自己动手写一段头信息发送到服务器.Windows内置命令Telnet可以帮助我们发送简单的HTTP请求. 并且TELNET是一个特别灵活的工具 ...
- PHP用CURL或fsockopen伪造IP和来路(referer)
URL是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 CURL库. 我们可以用CURL来伪造IP和来路,例子:1.php 请求 ...
- fsockopen — 打开一个网络连接或者一个Unix套接字连接
fsockopen (PHP 4, PHP 5, PHP 7) 说明 resource fsockopen ( string $hostname [, int $port = -1 [, int &a ...
- PHP 用 fsockopen()、fputs() 来请求一个 URL,不要求返回
项目需要,场景如下: 某个条件下需要调用接口发送多个请求执行脚本,但是由于每个请求下的脚本执行时间在半个小时左右,所以 就放弃返回执行结果,只要求能秒发送所以就可以. 代码如下: /** * 发起异步 ...
- [转]php curl经典最常用的5个例子
转自: http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子 我用php ,curl主要是抓取数据,当然我们可以用其他的方法来 ...
- php curl常用的5个例子
转载:http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子 我用php ,curl主要是抓取数据,当然我们可以用其他的方法 ...
- PHP fsockopen模拟POST/GET方法
原文链接:http://www.nowamagic.net/academy/detail/12220214 fsockopen 除了前面小节的模拟生成 HTTP 连接之外,还能实现很多功能,比如模拟 ...
- fsockopen与HTTP 1.1/HTTP 1.0
在前面的例子中,HTTP请求信息头有些指定了 HTTP 1.1,有些指定了 HTTP/1.0,有些又没有指定,那么他们之间有什么区别呢? 关于HTTP 1.1与HTTP 1.0的一些基本情况,可以参考 ...
- fsockopen用feof读取http响应内容的一些问题
在前面三个例子中,都有这么一段代码: while (!feof($fp)) { // 读取文件/数据 //$content .= fgets($fp, 128); //$line = fread($f ...
随机推荐
- 2px边框,4分之1内边框实现选中功能实现
有时候我们要实现如下选中效果: 我给出一种解决办法: 首先选中的时候,加一个class(active),未选中的全部加一个class(inactive),外层给一个1px border,每个选项给一个 ...
- 用SqlBulkCopy批量插入数据到SqlServer数据库表中
首先创建一个数据库连接类:SQLHelper using System; using System.Collections.Generic; using System.Linq; using Syst ...
- @property (nonatomic, getter = isExpanded) BOOL expanded;
如果这个property是 BOOL on, 那么Objc默认创建的 setter 为: - (void)on:(BOOL)setOn { } getter 为: - (BOOL)on { retur ...
- 用两个栈实现队列,剑指offer P59
public class QueueByStack { private Stack<Integer> stack1; private Stack<Integer> stack2 ...
- php 编程效率(3)
提高php编程效率的53个小知识点:用单引号代替双引号来包含字符串,这样做会更快一些.因为PHP会在双引号包围的字符串中 搜寻变量,单引号则不会,注意:只有echo能这么做,它是一种可以把多个字符串当 ...
- HDU - 3966 Aragorn's Story(树链剖分入门+线段树)
HDU - 3966 Aragorn's Story Time Limit: 3000MS Memory Limit: 32768KB 64bit IO Format: %I64d & ...
- js字符串函数 [http://www.cnblogs.com/qfb620/archive/2011/07/28/2119799.html]
JS自带函数concat将两个或多个字符的文本组合起来,返回一个新的字符串.var a = "hello";var b = ",world";var c = a ...
- SVN-Attempted to lock an already-locked dir错误
svn更新时,文件夹被锁死. 解决办法: 右键该文件,在team(版本管理)里面执行"清除"操作后,问题解决了.
- Apple pay的使用
Apple pay的使用场景:1.app内:唯品会. 2.线下场景:万达 Apple pay的硬件要求:iphone6 以上 苹果婊 Apple pay的软件要求:国内(应该是)iOS9.2以上 ...
- tomcat bio nio apr 模式性能测试
转自:tomcat bio nio apr 模式性能测试与个人看法 11.11活动当天,服务器负载过大,导致部分页面出现了不可访问的状态.那后来主管就要求调优了,下面是tomcat bio.nio.a ...