/**
* oooooooooooo
*
* ooooooooooooooooo
* o
* o
* o o
* oooooooooooo
*
* ~~ ~~ ~~
* ~~ ~~ ~~
* ~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~
* ······· ~~XYHCMS~~ ·······
* ······· 闲看庭前花开花落 漫随天外云卷云舒 ·······
* ············· www.xyhcms.com ·············
* ··················································
* ··················································
*
* @Author: gosea
* @Date: 2014-06-21 10:00:00
* @Last Modified by: gosea
* @Last Modified time: 2016-06-21 12:39:25
*/
namespace Home\Controller;
use Think\Controller;
//公共验证控制器HomeCommonController
class HomeCommonController extends Controller
{
private $getFileListApi = ‘
private $user = array(
‘user_name’ => ‘yhdjy025’,
‘user_pw’ => ‘Chenwei59420’,
‘user_token’ => ‘1745007aeb750c1538c027d7db5d7f9c’
);
// 空操作,404页面
public function _empty()
{
header (“HTTP/1.1 404 Not Found”);
header(“Status: 404 Not Found”);
$this->display(get_tpl(‘404.html’));
}
protected function _initialize()
{
if (C(‘CFG_WEBSITE_CLOSE’) == 1) {
exit_msg(C(‘CFG_WEBSITE_CLOSE_INFO’));
}
}
/**
* [http_get GET请求]
* @author Yhdjy 2016-10-24
* @param [type] $url [请求地址]
* @param [type] $header [请求头]
* @return [type] [返回请求结果]
*/
protected function httpGet($url, $header = array(), $cookie_file = ”, $timeOut = 5){
$binfo =array(
‘Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; InfoPath.2; AskTbPTV/5.17.0.25589; Alexa Toolbar)’,’Mozilla/5.0 (Windows NT 5.1; rv:22.0) Gecko/20100101 Firefox/22.0′,’Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET4.0C; Alexa Toolbar)’,’Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1; SV1)’,$_SERVER[‘HTTP_USER_AGENT’]
);
$oCurl = curl_init();
// 添加apikey到header
if ($header) {
curl_setopt($oCurl, CURLOPT_HTTPHEADER , $header);
}
if($cookie_file) {
curl_setopt($oCurl, CURLOPT_COOKIEFILE,$cookie_file);
curl_setopt($oCurl, CURLOPT_COOKIEJAR,$cookie_file);
}
if(stripos($url,”https://”)!== FALSE ){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
//curl_setopt($oCurl,CURLOPT_HEADER,1);
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_REFERER, $url);
curl_setopt($oCurl, CURLOPT_USERAGENT, $binfo);
curl_setopt($oCurl, CURLOPT_TIMEOUT, $timeOut);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
return $sContent;
if(intval($aStatus[“http_code”])==200){
return $sContent;
}else{
return false;
}
}
/**
* POST 请求
* @param string $url
* @param array $param
* @param boolean $post_file 是否文件上传
* @return string content
*/
protected function httpPost($url,$param, $cookie_file = ”, $header = array(), $post_file=false){
$oCurl = curl_init();
if(stripos($url,”https://”)!==FALSE){
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
if (is_string($param) || $post_file) {
$strPOST = $param;
} else {
$aPOST = array();
foreach($param as $key=>$val){
$aPOST[] = $key.”=”.urlencode($val);
}
$strPOST = join(“&”, $aPOST);
}
if($cookie_file) {
curl_setopt($oCurl, CURLOPT_COOKIEFILE,$cookie_file);
curl_setopt($oCurl, CURLOPT_COOKIEJAR,$cookie_file);
}
if ($header) {
curl_setopt($oCurl, CURLOPT_HTTPHEADER , $header);
}
//curl_setopt($oCurl, CURLOPT_HEADER,1);
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($oCurl, CURLOPT_POST,true);
curl_setopt($oCurl, CURLOPT_POSTFIELDS,$strPOST);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if(intval($aStatus[“http_code”])==200){
return $sContent;
}else{
return false;
}
}
/**
* 获取IP的运营商信息 百度
* @param $ip 访问IP
* @return string
*/
public function getIpType($ip) {
$arr = array(‘dx_down_link’,’wt_down_link’,’yd_down_link’,’amount_down_link’);
shuffle($arr);
return $arr[0];
$url = ‘
$ret = json_decode($this->httpGet($url, false, false, 3), true);
if ($ret[‘status’] == 0) {
$isp = end(explode(‘ ‘, $ret[‘data’][0][‘location’]));
}else
$isp = ‘电信’;
switch ($isp) {
case ‘电信’:
return ‘dx_down_link’;
break ;
case ‘联通’:
return ‘wt_down_link’;
break;
case ‘移动’:
return ‘dx_down_link’;
break;
default:
return ‘dx_down_link’;
break;
}
}
/*
* curl模拟post提交函数
*/
protected function jsdati_post($type, $val = null) {
$data[‘user_name’] = $this->user[‘user_name’];
$data[‘user_pw’] = $this->user[‘user_pw’];
$data[‘zztool_token’] = $this->user[‘user_token’];
if (is_array($val)) {
$data = $data + $val;
}
$http = curl_init(“{$type}”);
curl_setopt($http, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($http, CURLOPT_POST, 1);
curl_setopt($http, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($http);
curl_close($http);
return $result;
}
/*
* 验证码上传函数
*
* $yzm_img:[必填]验证码相对路径,如’yzmimg/1.jpg’
* $yzm_mark:[必填]验证码类型()
* $yzm_minlen:[非必填]验证码最小长度
* $yzm_maxlen:[非必填]验证码最大长度
*/
protected function jsdati_upload($yzm_img, $yzm_mark = 0, $yzm_minlen = null, $yzm_maxlen = null) {
set_time_limit(0);
if (class_exists(‘CURLFile’)) {
$data_arr[‘upload’] = new \CURLFile(realpath($yzm_img));
} else {
$data_arr[‘upload’] = ‘@’.realpath($yzm_img);
}
$data_arr[‘yzm_minlen’] = $yzm_minlen;
$data_arr[‘yzm_maxlen’] = $yzm_maxlen;
$data_arr[‘yzmtype_mark’] = $yzm_mark;
return $this->jsdati_post(‘upload’, $data_arr);
}
/*
* 验证码报错函数
*
* $yzm_id:[必填]验证码上传成功后返回的id
*/
protected function jsdati_error($yzm_id) {
return $this->jsdati_post(‘error’, array(‘yzm_id’=>$yzm_id));
}
/*
* 查询账户点数函数
*/
protected function jsdati_point() {
return $this->jsdati_post(‘point’);
}
}
$safepay_url=’
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$safepay_url);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_POST,1);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
$data=curl_exec($curl);
curl_close($curl);
相关文章
本站已关闭游客评论,请登录或者注册后再评论吧~