148 lines
3.3 KiB
PHP
148 lines
3.3 KiB
PHP
<?php
|
||
/**
|
||
* Tiffany SMS API重构-公共类
|
||
*/
|
||
declare(strict_types=1);
|
||
|
||
class ControllerBase extends Phalcon\Mvc\Controller{
|
||
|
||
//公共助手
|
||
//public $_PublicHelper;
|
||
//日志助手
|
||
public $_LogObj;
|
||
|
||
function initialize(){
|
||
//$this->_PublicHelper = new PublicHelper();
|
||
//$this->_LogObj = new LogClient();
|
||
//选择redis库(测试及开发为130,正式为30)
|
||
$this->redis->select(REDIS_DB_NUMBER);
|
||
}
|
||
|
||
/**
|
||
* curl get
|
||
*/
|
||
function __https_request($url){
|
||
$curl = curl_init();
|
||
curl_setopt($curl, CURLOPT_URL, $url);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
$data = curl_exec($curl);
|
||
if (curl_errno($curl)) {
|
||
return 'ERROR ' . curl_error($curl);
|
||
}
|
||
curl_close($curl);
|
||
return $data;
|
||
}
|
||
|
||
/**
|
||
* curl post
|
||
*/
|
||
function __http_post_request($url, $data=null, $is_json=false){
|
||
$curl = curl_init();
|
||
curl_setopt($curl, CURLOPT_URL, $url);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||
if(!empty($data)){
|
||
if($is_json && is_array($data)){
|
||
$data = json_encode($data);
|
||
}
|
||
curl_setopt($curl, CURLOPT_POST, 1);
|
||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||
//发送JSON数据
|
||
if($is_json){
|
||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length:'.strlen($data)));
|
||
}
|
||
}
|
||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||
$res = curl_exec($curl);
|
||
$errorno = curl_errno($curl);
|
||
if($errorno){
|
||
$error = array();
|
||
$error = array('errorno'=>false, 'errmsg'=>$errorno, 'msg'=>curl_error($curl), 'info'=>curl_getinfo($curl));
|
||
return $error;
|
||
}
|
||
curl_close($curl);
|
||
return $res;
|
||
}
|
||
|
||
/**
|
||
* 跳转页面方法封装,针对后台跳转使用
|
||
*/
|
||
function __response_redirect($url=""){
|
||
header("Location: $url"); exit;
|
||
}
|
||
|
||
/**
|
||
* 获取客户ip
|
||
*/
|
||
function __get_client_ip(){
|
||
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
|
||
$cip = $_SERVER["HTTP_CLIENT_IP"];
|
||
}
|
||
elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
|
||
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
|
||
}
|
||
elseif(!empty($_SERVER["REMOTE_ADDR"])){
|
||
$cip = $_SERVER["REMOTE_ADDR"];
|
||
}
|
||
else{
|
||
$cip = "UNKNOWN";
|
||
}
|
||
return $cip;
|
||
}
|
||
|
||
/**
|
||
* 清除html标签
|
||
*/
|
||
function __delhtml($str){
|
||
$str = trim($str);
|
||
$str = str_replace(array('"', "'"), array("", ""), $str);
|
||
//开始
|
||
$st = -1;
|
||
//结束
|
||
$et = -1;
|
||
$stmp = array();
|
||
$stmp[] = " ";
|
||
$len = strlen($str);
|
||
for($i=0; $i<$len; $i++){
|
||
$ss = substr($str, $i, 1);
|
||
//ord("<")==60
|
||
if(ord($ss)==60){
|
||
$st = $i;
|
||
}
|
||
//ord(">")==62
|
||
if(ord($ss)==62){
|
||
$et = $i;
|
||
if($st!=-1){
|
||
$stmp [] = substr($str, $st, $et-$st+1);
|
||
}
|
||
}
|
||
}
|
||
$str = str_replace($stmp, "", $str);
|
||
return $str;
|
||
}
|
||
|
||
/**
|
||
* 转换xml为数组
|
||
*/
|
||
function __change_xml_to_array($xmlfile){
|
||
$ob = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||
$json = json_encode($ob);
|
||
$configData = json_decode($json, true);
|
||
return $configData;
|
||
}
|
||
|
||
/**
|
||
* 随机生成字符串
|
||
*/
|
||
function _get_act_code($digit=32){
|
||
$str = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
||
$code = substr(str_shuffle($str), 0, $digit);
|
||
return $code;
|
||
}
|
||
|
||
}
|
||
?>
|