api/app/controllers/ControllerBase.php
2023-04-07 19:05:18 +08:00

137 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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, $postArr){
$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, CURL_SSLVERSION_TLSv1);
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArr);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
/**
* 跳转页面方法封装,针对后台跳转使用
*/
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[] = "&nbsp;";
$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;
}
/**
* 随机生成8位字符
*/
function _get_act_code(){
$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$code = substr(str_shuffle($str), 0, 8);
return $code;
}
}
?>