<?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例子的更多相关文章

  1. PHP模拟发送POST请求之三、用Telnet和fsockopen()模拟发送POST信息

    了解完了HTTP头信息和URL信息的具体内容,我们开始尝试自己动手写一段头信息发送到服务器.Windows内置命令Telnet可以帮助我们发送简单的HTTP请求. 并且TELNET是一个特别灵活的工具 ...

  2. PHP用CURL或fsockopen伪造IP和来路(referer)

    URL是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 CURL库. 我们可以用CURL来伪造IP和来路,例子:1.php 请求 ...

  3. fsockopen — 打开一个网络连接或者一个Unix套接字连接

    fsockopen (PHP 4, PHP 5, PHP 7) 说明 resource fsockopen ( string $hostname [, int $port = -1 [, int &a ...

  4. PHP 用 fsockopen()、fputs() 来请求一个 URL,不要求返回

    项目需要,场景如下: 某个条件下需要调用接口发送多个请求执行脚本,但是由于每个请求下的脚本执行时间在半个小时左右,所以 就放弃返回执行结果,只要求能秒发送所以就可以. 代码如下: /** * 发起异步 ...

  5. [转]php curl经典最常用的5个例子

    转自: http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子 我用php ,curl主要是抓取数据,当然我们可以用其他的方法来 ...

  6. php curl常用的5个例子

    转载:http://www.jb100.net/html/content-22-821-1.html php curl常用的5个例子   我用php ,curl主要是抓取数据,当然我们可以用其他的方法 ...

  7. PHP fsockopen模拟POST/GET方法

    原文链接:http://www.nowamagic.net/academy/detail/12220214 fsockopen 除了前面小节的模拟生成 HTTP 连接之外,还能实现很多功能,比如模拟  ...

  8. fsockopen与HTTP 1.1/HTTP 1.0

    在前面的例子中,HTTP请求信息头有些指定了 HTTP 1.1,有些指定了 HTTP/1.0,有些又没有指定,那么他们之间有什么区别呢? 关于HTTP 1.1与HTTP 1.0的一些基本情况,可以参考 ...

  9. fsockopen用feof读取http响应内容的一些问题

    在前面三个例子中,都有这么一段代码: while (!feof($fp)) { // 读取文件/数据 //$content .= fgets($fp, 128); //$line = fread($f ...

随机推荐

  1. JDK7 LinkedList源代码分析

    transient int size = 0; /** * Pointer to first node. * Invariant: (first == null && last == ...

  2. Ansible 变量

    1. 变量来源 inventoryfile中定义 playbook中定义 include文件和角色中定义变量 系统facts  ansible hostname -m setup local fact ...

  3. 8、关于viewWithTag

    1.viewWithTag检索tag的方法问题viewWithTag方法会对当前View和其子View进行搜索,查找符合tag的对象,但如果view和其多个子view中都含有相同tag值对象时,该方法 ...

  4. javaMail邮件发送的简单实现

    package com.test.mail; import java.util.Properties; import javax.mail.Message; import javax.mail.Ses ...

  5. 浏览器exp使用经验

    0x00背景 windows平台下,浏览器安全是绕不过的话题,其涉及的安全问题涵盖二进制和web,攻击场景也非常多样化: 用户点击攻击者的恶意URL链接被感染恶意代码 访问恶意站点被绕过同源策略窃取c ...

  6. 【.NET】加密和解密(.NET)

    类名:Security using System; using System.Security.Cryptography; using System.IO; using System.Text; na ...

  7. blog地址

    1  Java 设计模式  http://www.cnblogs.com/java-my-life/

  8. winform上传文件

    //上传图片 文件 public int addUpPic( String strProCode,String strFileName,String strUpType) { //strFileNam ...

  9. 淘淘商城_day04_课堂笔记

    今日大纲 实现首页的大广告位功能 实现内容管理系统 首页的大广告 什么是大广告 JS效果: 点击下面的序号选择查询哪个广告 自动切换 点击图片查询具体的页面 以上是由前端团队来开发. 数据结构 说明: ...

  10. 第一百零四节,JavaScript时间与日期

    JavaScript时间与日期 学习要点: 1.Date类型 2.通用的方法 3.格式化方法 4.组件方法 ECMAScript提供了Date类型来处理时间和日期.Date类型内置一系列获取和设置日期 ...