first commit
This commit is contained in:
@@ -0,0 +1,511 @@
|
||||
<?php
|
||||
/**
|
||||
* Http Curl 工具类
|
||||
* @author jackhe
|
||||
* @email itjackhe@163.com
|
||||
* @version v1.0.0
|
||||
* @date 2018-06-21
|
||||
*/
|
||||
class HttpCurl{
|
||||
|
||||
/**
|
||||
* @var resource cURL句柄
|
||||
*/
|
||||
private $ch = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var string 响应数据格式 text|json
|
||||
*/
|
||||
private $dataType = 'text';
|
||||
|
||||
|
||||
/**
|
||||
* @var string 请求的url
|
||||
*/
|
||||
private $url = '';
|
||||
|
||||
/**
|
||||
* @var int 超时秒数
|
||||
*/
|
||||
private $timeOut = 3;
|
||||
|
||||
|
||||
/**
|
||||
* @var array 请求携带数据
|
||||
*/
|
||||
private $data = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var array http header
|
||||
*/
|
||||
private $header = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var string http userAgent
|
||||
*/
|
||||
private $userAgent = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var string http proxy
|
||||
*/
|
||||
private $proxy = null;
|
||||
|
||||
|
||||
/**
|
||||
* @var int http proxyPort
|
||||
*/
|
||||
private $proxyPort = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var int http 是否显示header信息
|
||||
*/
|
||||
private $showHeader = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var string 来源页面地址
|
||||
*/
|
||||
private $referer = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var string 证书地址
|
||||
*/
|
||||
private $cainfo = null;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @var int 最后一次 请求的http响应码
|
||||
*/
|
||||
private $http_code = 0;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @return $this
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//判断php版本、小于 5.3.0 提示用户更新
|
||||
if(version_compare(PHP_VERSION,'5.3.0', '<')){
|
||||
exit('<h1>Please upgrade PHP version to 5.3+</h1>');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置 http header
|
||||
* @access private
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param array $header http header
|
||||
* @return $this
|
||||
*/
|
||||
public function header($header = null) {
|
||||
$this->header = $header;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置用户代理
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $agent 用户代理
|
||||
* @return $this
|
||||
*/
|
||||
public function userAgent($agent = null)
|
||||
{
|
||||
$this->userAgent = $agent;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置用户代理
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $url 请求的url
|
||||
* @param array $data 请求携带数据
|
||||
* @return $this
|
||||
*/
|
||||
public function timeout($timeout = 0)
|
||||
{
|
||||
//判断小于 1 、设置最小 为 3秒
|
||||
if($timeout < 1){
|
||||
$timeout = 3;
|
||||
}
|
||||
//这种
|
||||
$this->timeOut = $timeout;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置 http 代理
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $url 代理地址
|
||||
* @return $this
|
||||
*/
|
||||
public function proxy($proxy)
|
||||
{
|
||||
$this->proxy = $proxy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置 http 代理端口
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param int $port 代理端口
|
||||
* @return $this
|
||||
*/
|
||||
public function proxyPort($port)
|
||||
{
|
||||
$this->proxyPort = $port;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置http响应header头
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param bool $show 是否显示
|
||||
* @return $this
|
||||
*/
|
||||
public function showHeader($show = 0)
|
||||
{
|
||||
$show = $show == 1 || $show === true ? 1 : 0;
|
||||
$this->showHeader = $show;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置来源页面地址
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $referer 来源地址
|
||||
* @return $this
|
||||
*/
|
||||
public function referer($referer = null){
|
||||
$this->referer = $referer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置证书路径
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $path 证书路径
|
||||
* @return $this
|
||||
*/
|
||||
public function cainfo($path) {
|
||||
$this->cainfo = $path;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 响应数据格式 text|json
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $type 响应数据格式
|
||||
* @return $this
|
||||
*/
|
||||
public function dataType($type = 'text') {
|
||||
$this->dataType = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置请求携带数据
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param array $data 请求携带的参数
|
||||
* @return $this
|
||||
*/
|
||||
public function data($data = null){
|
||||
|
||||
if(!empty($data)){
|
||||
$this->data = $data;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 设置请求url地址
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $url 请求的url地址
|
||||
* @return $this
|
||||
*/
|
||||
public function url($url = null){
|
||||
|
||||
if(!empty($url)){
|
||||
$this->url = $url;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取最后一次请求的 http_code
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @return int
|
||||
*/
|
||||
public function getLastHttpCode(){
|
||||
return $this->http_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* get 请求方法
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $url 请求的url
|
||||
* @param array $data 请求携带数据
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($url,$data = null)
|
||||
{
|
||||
//设置 请求url
|
||||
$this->url($url);
|
||||
//设置 请求携带数据
|
||||
$this->data($data);
|
||||
$this->ch = curl_init();
|
||||
//设置 get 参数
|
||||
if((!empty($this->data)) && is_array($this->data)){
|
||||
//判断 url 存在 ?
|
||||
if(strpos($this->url,'?') !== false){
|
||||
$this->url .= http_build_query($this->data);
|
||||
}else{
|
||||
$this->url .= '?' . http_build_query($this->data);
|
||||
}
|
||||
}
|
||||
|
||||
//执行 http请求 并 返回响应内容
|
||||
return $this->httpRequest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* post 请求方法
|
||||
* @access public
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @param string $url 请求的url
|
||||
* @param array || string $data 数据
|
||||
* @return mixed
|
||||
*/
|
||||
public function post($url,$data= null)
|
||||
{
|
||||
|
||||
//设置 请求url
|
||||
$this->url($url);
|
||||
//设置 file路径数组
|
||||
$this->data($data);
|
||||
$this->ch = curl_init();
|
||||
curl_setopt($this->ch, CURLOPT_POST, 1);
|
||||
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
|
||||
// 设置post内容
|
||||
if(!empty($this->data)) {
|
||||
$data = array();
|
||||
//判断是字符串 并且 存在
|
||||
if(is_string($this->data)){
|
||||
$data = $this->data;
|
||||
}
|
||||
|
||||
//判断是数组 并且 存在
|
||||
if(is_array($this->data) && (!empty($this->data))){
|
||||
foreach ($this->data as $key=>$val){
|
||||
|
||||
if(stripos($val,'@') === 0){
|
||||
$val = trim($val,'@');
|
||||
if(version_compare(PHP_VERSION,'5.5.0', '>=')){
|
||||
$data[$key] = new CURLFile(realpath($val));
|
||||
}else{
|
||||
$data[$key] = '@'.realpath($val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
|
||||
}
|
||||
|
||||
//执行 http请求 并 返回响应内容
|
||||
return $this->httpRequest();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* http 请求方法
|
||||
* @access private
|
||||
* @author jackhe
|
||||
* @date 2018-06-21
|
||||
* @return mixed
|
||||
*/
|
||||
private function httpRequest(){
|
||||
|
||||
//设置超时秒数
|
||||
curl_setopt($this->ch, CURLOPT_TIMEOUT, $this->timeOut);
|
||||
|
||||
//http请求头
|
||||
if(is_array($this->header)){
|
||||
curl_setopt($this->ch, CURLOPT_HTTPHEADER , $this->header);
|
||||
}
|
||||
|
||||
//http头信息是否显示
|
||||
if(is_array($this->header)){
|
||||
curl_setopt($this->ch, CURLOPT_HEADER, $this->showHeader);
|
||||
}
|
||||
|
||||
//用户代理
|
||||
if($this->userAgent) {
|
||||
//设置模拟用户使用的浏览器
|
||||
curl_setopt($this->ch, CURLOPT_USERAGENT, $this->userAgent);
|
||||
}
|
||||
|
||||
//代理地址
|
||||
if($this->proxy){
|
||||
curl_setopt ($this->ch, CURLOPT_PROXY, $this->proxy);
|
||||
}
|
||||
|
||||
//代理端口
|
||||
if(is_int($this->proxyPort)){
|
||||
curl_setopt($this->ch, CURLOPT_PROXYPORT, $this->proxyPort);
|
||||
}
|
||||
|
||||
//来源页面地址
|
||||
if ($this->referer){
|
||||
curl_setopt($this->ch, CURLOPT_REFERER , $this->referer);
|
||||
}
|
||||
|
||||
//证书地址
|
||||
if($this->cainfo){
|
||||
curl_setopt($this->ch, CURLOPT_CAINFO, $this->cainfo);
|
||||
}
|
||||
|
||||
//处理 https
|
||||
if(stripos($this->url, 'https://') !== FALSE) {
|
||||
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||||
curl_setopt($this->ch, CURLOPT_SSLVERSION, 1);
|
||||
}
|
||||
|
||||
//设置 url
|
||||
curl_setopt($this->ch, CURLOPT_URL, $this->url);
|
||||
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1 );
|
||||
|
||||
//执行请求
|
||||
$content = curl_exec($this->ch);
|
||||
//获取请求 http_code
|
||||
$this->http_code = curl_getinfo($this->ch,CURLINFO_HTTP_CODE);
|
||||
//关闭 curl 句柄
|
||||
curl_close($this->ch);
|
||||
$this->ch = null;
|
||||
$this->data = null;
|
||||
//200状态码
|
||||
if($this->http_code == 200) {
|
||||
//json格式
|
||||
if($this->dataType == 'json'){
|
||||
//返回数组
|
||||
return json_decode($content,true);
|
||||
}
|
||||
return $content;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/*
|
||||
* File:RSA通用加解密
|
||||
* Author:易如意
|
||||
* QQ:51154393
|
||||
* url:www.eruyi.cn
|
||||
** 注意:请勿使用记事本修改,保存时必须保证以《 UTF8 无 BOM 格式编码》,否则会影响返回的数据
|
||||
*/
|
||||
class Rsa{
|
||||
|
||||
/**
|
||||
* 签名算法,SHA256WithRSA
|
||||
*/
|
||||
|
||||
const SIGNATURE_ALGORITHM = OPENSSL_ALGO_SHA256;
|
||||
|
||||
/**
|
||||
* RSA最大加密明文大小
|
||||
*/
|
||||
const MAX_ENCRYPT_BLOCK = 117;
|
||||
|
||||
/**
|
||||
* RSA最大解密密文大小
|
||||
*/
|
||||
const MAX_DECRYPT_BLOCK = 128;
|
||||
|
||||
/**
|
||||
* 使用公钥将数据加密
|
||||
* @param $data string 需要加密的数据
|
||||
* @param $publicKey string 公钥
|
||||
* @return string 返回加密串(base64编码)
|
||||
*/
|
||||
public static function publicEncrypt($data,$publicKey){
|
||||
$data = str_split($data, self::MAX_ENCRYPT_BLOCK);
|
||||
|
||||
$encrypted = '';
|
||||
foreach($data as & $chunk){
|
||||
if(!openssl_public_encrypt($chunk, $encryptData, "-----BEGIN PUBLIC KEY-----\n".$publicKey."\n-----END PUBLIC KEY-----")){
|
||||
return '';
|
||||
}else{
|
||||
$encrypted .= $encryptData;
|
||||
}
|
||||
}
|
||||
return self::urlSafeBase64encode($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用私钥解密
|
||||
* @param $data string 需要解密的数据
|
||||
* @param $privateKey string 私钥
|
||||
* @return string 返回解密串
|
||||
*/
|
||||
public static function privateDecrypt($data,$privateKey){
|
||||
$data = str_split(self::urlSafeBase64decode($data), self::MAX_DECRYPT_BLOCK);
|
||||
|
||||
$decrypted = '';
|
||||
foreach($data as & $chunk){
|
||||
if(!openssl_private_decrypt($chunk, $decryptData, "-----BEGIN RSA PRIVATE KEY-----\n".$privateKey."\n-----END RSA PRIVATE KEY-----")){
|
||||
return '';
|
||||
}else{
|
||||
$decrypted .= $decryptData;
|
||||
}
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用私钥将数据加密
|
||||
* @param $data string 需要加密的数据
|
||||
* @param $privateKey string 私钥
|
||||
* @return string 返回加密串(base64编码)
|
||||
*/
|
||||
public static function privateEncrypt($data,$privateKey){
|
||||
$data = str_split($data, self::MAX_ENCRYPT_BLOCK);
|
||||
|
||||
$encrypted = '';
|
||||
foreach($data as & $chunk){
|
||||
if(!openssl_private_encrypt($chunk, $encryptData, "-----BEGIN RSA PRIVATE KEY-----\n".$privateKey."\n-----END RSA PRIVATE KEY-----")){
|
||||
return '';
|
||||
}else{
|
||||
$encrypted .= $encryptData;
|
||||
}
|
||||
}
|
||||
return self::urlSafeBase64encode($encrypted);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 使用公钥解密
|
||||
* @param $data string 需要解密的数据
|
||||
* @param $publicKey string 公钥
|
||||
* @return string 返回解密串
|
||||
*/
|
||||
public static function publicDecrypt($data,$publicKey){
|
||||
$data = str_split(self::urlSafeBase64decode($data), self::MAX_DECRYPT_BLOCK);
|
||||
|
||||
$decrypted = '';
|
||||
foreach($data as & $chunk){
|
||||
if(!openssl_public_decrypt($chunk, $decryptData, "-----BEGIN PUBLIC KEY-----\n".$publicKey."\n-----END PUBLIC KEY-----")){
|
||||
return '';
|
||||
}else{
|
||||
$decrypted .= $decryptData;
|
||||
}
|
||||
}
|
||||
return $decrypted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 私钥加签名
|
||||
* @param $data 被加签数据
|
||||
* @param $privateKey 私钥
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function rsaSign($data, $privateKey){
|
||||
if(openssl_sign($data, $sign, "-----BEGIN RSA PRIVATE KEY-----\n".$privateKey."\n-----END RSA PRIVATE KEY-----", self::SIGNATURE_ALGORITHM)){
|
||||
return self::urlSafeBase64encode($sign);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥验签
|
||||
* @param $data 被加签数据
|
||||
* @param $sign 签名
|
||||
* @param $publicKey 公钥
|
||||
* @return bool
|
||||
*/
|
||||
public static function verifySign($data, $sign, $publicKey){
|
||||
return (1 == openssl_verify($data, self::urlSafeBase64decode($sign), "-----BEGIN PUBLIC KEY-----\n".$publicKey."\n-----END PUBLIC KEY-----", self::SIGNATURE_ALGORITHM));
|
||||
}
|
||||
|
||||
/**
|
||||
* url base64编码
|
||||
* @param $string
|
||||
* @return mixed|string
|
||||
*/
|
||||
public static function urlSafeBase64encode($string,$replace = false){
|
||||
if($replace){
|
||||
$data = str_replace(array('+','/','='), array( '-','_',''), base64_encode($string));
|
||||
}else{
|
||||
$data = base64_encode($string);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* url base64解码
|
||||
* @param $string
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function urlSafeBase64decode($string,$replace = false){
|
||||
if($replace){
|
||||
$data = str_replace(array('-','_'), array('+','/'), $string);
|
||||
$mod4 = strlen($data) % 4;
|
||||
if($mod4){
|
||||
$data .= substr('====', $mod4);
|
||||
}
|
||||
}else{
|
||||
$data = $string;
|
||||
}
|
||||
return base64_decode($data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/*
|
||||
* File:操作类
|
||||
* Author:易如意
|
||||
* QQ:51154393
|
||||
* Url:www.eruyi.cn
|
||||
*/
|
||||
|
||||
class Array_to_Xml{
|
||||
private $version = '1.0';
|
||||
private $encoding = 'UTF-8';
|
||||
private $root = 'eruyi';
|
||||
private $xml = null;
|
||||
function __construct()
|
||||
{
|
||||
$this->xml = new XmlWriter();
|
||||
}
|
||||
function toXml($data, $eIsArray=FALSE)
|
||||
{
|
||||
if(!$eIsArray)
|
||||
{
|
||||
$this->xml->openMemory();
|
||||
$this->xml->startDocument($this->version, $this->encoding);
|
||||
$this->xml->startElement($this->root);
|
||||
}
|
||||
foreach($data as $key => $value)
|
||||
{
|
||||
if(is_array($value))
|
||||
{
|
||||
$this->xml->startElement($key);
|
||||
$this->toXml($value, TRUE);
|
||||
$this->xml->endElement();
|
||||
continue;
|
||||
}
|
||||
$this->xml->writeElement($key, $value);
|
||||
}
|
||||
if(!$eIsArray)
|
||||
{
|
||||
$this->xml->endElement();
|
||||
return $this->xml->outputMemory(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer language file: refer to English translation for definitive list
|
||||
* Chinese Version
|
||||
* By LiuXin: www.80x86.cn/blog/
|
||||
*/
|
||||
|
||||
$PHPMAILER_LANG['authenticate'] = 'SMTP 错误:身份验证失败。';
|
||||
$PHPMAILER_LANG['connect_host'] = 'SMTP 错误: 不能连接SMTP主机。';
|
||||
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP 错误: 数据不可接受。';
|
||||
//$PHPMAILER_LANG['empty_message'] = 'Message body empty';
|
||||
$PHPMAILER_LANG['encoding'] = '未知编码:';
|
||||
$PHPMAILER_LANG['execute'] = '不能执行: ';
|
||||
$PHPMAILER_LANG['file_access'] = '不能访问文件:';
|
||||
$PHPMAILER_LANG['file_open'] = '文件错误:不能打开文件:';
|
||||
$PHPMAILER_LANG['from_failed'] = '下面的发送地址邮件发送失败了: ';
|
||||
$PHPMAILER_LANG['instantiate'] = '不能实现mail方法。';
|
||||
//$PHPMAILER_LANG['invalid_email'] = 'Not sending, email address is invalid: ';
|
||||
$PHPMAILER_LANG['mailer_not_supported'] = ' 您所选择的发送邮件的方法并不支持。';
|
||||
$PHPMAILER_LANG['provide_address'] = '您必须提供至少一个 收信人的email地址。';
|
||||
$PHPMAILER_LANG['recipients_failed'] = 'SMTP 错误: 下面的 收件人失败了: ';
|
||||
//$PHPMAILER_LANG['signing'] = 'Signing Error: ';
|
||||
//$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() failed.';
|
||||
//$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
|
||||
//$PHPMAILER_LANG['variable_set'] = 'Cannot set or reset variable: ';
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer language file: refer to English translation for definitive list
|
||||
* Spanish version
|
||||
* Versión en español
|
||||
*/
|
||||
|
||||
$PHPMAILER_LANG['authenticate'] = 'Error SMTP: No se pudo autentificar.';
|
||||
$PHPMAILER_LANG['connect_host'] = 'Error SMTP: No puedo conectar al servidor SMTP.';
|
||||
$PHPMAILER_LANG['data_not_accepted'] = 'Error SMTP: Datos no aceptados.';
|
||||
//$PHPMAILER_LANG['empty_message'] = 'Message body empty';
|
||||
$PHPMAILER_LANG['encoding'] = 'Codificación desconocida: ';
|
||||
$PHPMAILER_LANG['execute'] = 'No puedo ejecutar: ';
|
||||
$PHPMAILER_LANG['file_access'] = 'No puedo acceder al archivo: ';
|
||||
$PHPMAILER_LANG['file_open'] = 'Error de Archivo: No puede abrir el archivo: ';
|
||||
$PHPMAILER_LANG['from_failed'] = 'La(s) siguiente(s) direcciones de remitente fallaron: ';
|
||||
$PHPMAILER_LANG['instantiate'] = 'No pude crear una instancia de la función Mail.';
|
||||
//$PHPMAILER_LANG['invalid_email'] = 'Not sending, email address is invalid: ';
|
||||
$PHPMAILER_LANG['mailer_not_supported'] = ' mailer no está soportado.';
|
||||
$PHPMAILER_LANG['provide_address'] = 'Debe proveer al menos una dirección de email como destinatario.';
|
||||
$PHPMAILER_LANG['recipients_failed'] = 'Error SMTP: Los siguientes destinatarios fallaron: ';
|
||||
$PHPMAILER_LANG['signing'] = 'Error al firmar: ';
|
||||
//$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() failed.';
|
||||
//$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
|
||||
//$PHPMAILER_LANG['variable_set'] = 'Cannot set or reset variable: ';
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer language file: refer to English translation for definitive list
|
||||
* Traditional Chinese Version
|
||||
* @author liqwei <liqwei@liqwei.com>
|
||||
*/
|
||||
|
||||
$PHPMAILER_LANG['authenticate'] = 'SMTP 錯誤:登錄失敗。';
|
||||
$PHPMAILER_LANG['connect_host'] = 'SMTP 錯誤:無法連接到 SMTP 主機。';
|
||||
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP 錯誤:數據不被接受。';
|
||||
//$PHPMAILER_LANG['empty_message'] = 'Message body empty';
|
||||
$PHPMAILER_LANG['encoding'] = '未知編碼: ';
|
||||
$PHPMAILER_LANG['file_access'] = '無法訪問文件:';
|
||||
$PHPMAILER_LANG['file_open'] = '文件錯誤:無法打開文件:';
|
||||
$PHPMAILER_LANG['from_failed'] = '發送地址錯誤:';
|
||||
$PHPMAILER_LANG['execute'] = '無法執行:';
|
||||
$PHPMAILER_LANG['instantiate'] = '未知函數調用。';
|
||||
//$PHPMAILER_LANG['invalid_email'] = 'Not sending, email address is invalid: ';
|
||||
$PHPMAILER_LANG['provide_address'] = '必須提供至少一個收件人地址。';
|
||||
$PHPMAILER_LANG['mailer_not_supported'] = '發信客戶端不被支持。';
|
||||
$PHPMAILER_LANG['recipients_failed'] = 'SMTP 錯誤:收件人地址錯誤:';
|
||||
//$PHPMAILER_LANG['signing'] = 'Signing Error: ';
|
||||
//$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP Connect() failed.';
|
||||
//$PHPMAILER_LANG['smtp_error'] = 'SMTP server error: ';
|
||||
//$PHPMAILER_LANG['variable_set'] = 'Cannot set or reset variable: ';
|
||||
?>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPMailer language file: refer to English translation for definitive list
|
||||
* Simplified Chinese Version
|
||||
* @author liqwei <liqwei@liqwei.com>
|
||||
*/
|
||||
|
||||
$PHPMAILER_LANG['authenticate'] = 'SMTP 错误:登录失败。';
|
||||
$PHPMAILER_LANG['connect_host'] = 'SMTP 错误:无法连接到 SMTP 主机。';
|
||||
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP 错误:数据不被接受。';
|
||||
$PHPMAILER_LANG['empty_message'] = '邮件内容不能为空';
|
||||
$PHPMAILER_LANG['encoding'] = '未知编码: ';
|
||||
$PHPMAILER_LANG['execute'] = '无法执行:';
|
||||
$PHPMAILER_LANG['file_access'] = '无法访问文件:';
|
||||
$PHPMAILER_LANG['file_open'] = '文件错误:无法打开文件:';
|
||||
$PHPMAILER_LANG['from_failed'] = '发送地址错误:';
|
||||
$PHPMAILER_LANG['instantiate'] = '未知函数调用。';
|
||||
$PHPMAILER_LANG['invalid_email'] = '没有发送,电子邮件地址是无效的: ';
|
||||
$PHPMAILER_LANG['mailer_not_supported'] = '发信客户端不被支持。';
|
||||
$PHPMAILER_LANG['provide_address'] = '必须提供至少一个收件人地址。';
|
||||
$PHPMAILER_LANG['recipients_failed'] = 'SMTP 错误:收件人地址错误:';
|
||||
$PHPMAILER_LANG['signing'] = '签名错误: ';
|
||||
$PHPMAILER_LANG['smtp_connect_failed'] = 'SMTP 连接错误.';
|
||||
$PHPMAILER_LANG['smtp_error'] = 'SMTP服务器错误: ';
|
||||
$PHPMAILER_LANG['variable_set'] = '不能设置或重置变量: ';
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,814 @@
|
||||
<?php
|
||||
/*~ class.smtp.php
|
||||
.---------------------------------------------------------------------------.
|
||||
| Software: PHPMailer - PHP email class |
|
||||
| Version: 5.1 |
|
||||
| Contact: via sourceforge.net support pages (also www.codeworxtech.com) |
|
||||
| Info: http://phpmailer.sourceforge.net |
|
||||
| Support: http://sourceforge.net/projects/phpmailer/ |
|
||||
| ------------------------------------------------------------------------- |
|
||||
| Admin: Andy Prevost (project admininistrator) |
|
||||
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
|
||||
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
|
||||
| Founder: Brent R. Matzelle (original founder) |
|
||||
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
|
||||
| Copyright (c) 2001-2003, Brent R. Matzelle |
|
||||
| ------------------------------------------------------------------------- |
|
||||
| License: Distributed under the Lesser General Public License (LGPL) |
|
||||
| http://www.gnu.org/copyleft/lesser.html |
|
||||
| This program is distributed in the hope that it will be useful - WITHOUT |
|
||||
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
||||
| FITNESS FOR A PARTICULAR PURPOSE. |
|
||||
| ------------------------------------------------------------------------- |
|
||||
| We offer a number of paid services (www.codeworxtech.com): |
|
||||
| - Web Hosting on highly optimized fast and secure servers |
|
||||
| - Technology Consulting |
|
||||
| - Oursourcing (highly qualified programmers and graphic designers) |
|
||||
'---------------------------------------------------------------------------'
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPMailer - PHP SMTP email transport class
|
||||
* NOTE: Designed for use with PHP version 5 and up
|
||||
* @package PHPMailer
|
||||
* @author Andy Prevost
|
||||
* @author Marcus Bointon
|
||||
* @copyright 2004 - 2008 Andy Prevost
|
||||
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
|
||||
* @version $Id: class.smtp.php 444 2009-05-05 11:22:26Z coolbru $
|
||||
*/
|
||||
|
||||
/**
|
||||
* SMTP is rfc 821 compliant and implements all the rfc 821 SMTP
|
||||
* commands except TURN which will always return a not implemented
|
||||
* error. SMTP also provides some utility methods for sending mail
|
||||
* to an SMTP server.
|
||||
* original author: Chris Ryan
|
||||
*/
|
||||
|
||||
class SMTP {
|
||||
/**
|
||||
* SMTP server port
|
||||
* @var int
|
||||
*/
|
||||
public $SMTP_PORT = 25;
|
||||
|
||||
/**
|
||||
* SMTP reply line ending
|
||||
* @var string
|
||||
*/
|
||||
public $CRLF = "\r\n";
|
||||
|
||||
/**
|
||||
* Sets whether debugging is turned on
|
||||
* @var bool
|
||||
*/
|
||||
public $do_debug; // the level of debug to perform
|
||||
|
||||
/**
|
||||
* Sets VERP use on/off (default is off)
|
||||
* @var bool
|
||||
*/
|
||||
public $do_verp = false;
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// PROPERTIES, PRIVATE AND PROTECTED
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
private $smtp_conn; // the socket to the server
|
||||
private $error; // error if any on the last call
|
||||
private $helo_rply; // the reply the server sent to us for HELO
|
||||
|
||||
/**
|
||||
* Initialize the class so that the data is in a known state.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->smtp_conn = 0;
|
||||
$this->error = null;
|
||||
$this->helo_rply = null;
|
||||
|
||||
$this->do_debug = 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// CONNECTION FUNCTIONS
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Connect to the server specified on the port specified.
|
||||
* If the port is not specified use the default SMTP_PORT.
|
||||
* If tval is specified then a connection will try and be
|
||||
* established with the server for that number of seconds.
|
||||
* If tval is not specified the default is 30 seconds to
|
||||
* try on the connection.
|
||||
*
|
||||
* SMTP CODE SUCCESS: 220
|
||||
* SMTP CODE FAILURE: 421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Connect($host, $port = 0, $tval = 30) {
|
||||
// set the error val to null so there is no confusion
|
||||
$this->error = null;
|
||||
|
||||
// make sure we are __not__ connected
|
||||
if($this->connected()) {
|
||||
// already connected, generate error
|
||||
$this->error = array("error" => "Already connected to a server");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(empty($port)) {
|
||||
$port = $this->SMTP_PORT;
|
||||
}
|
||||
|
||||
// connect to the smtp server
|
||||
$this->smtp_conn = @fsockopen($host, // the host of the server
|
||||
$port, // the port to use
|
||||
$errno, // error number if any
|
||||
$errstr, // error message if any
|
||||
$tval); // give up after ? secs
|
||||
// verify we connected properly
|
||||
if(empty($this->smtp_conn)) {
|
||||
$this->error = array("error" => "Failed to connect to server",
|
||||
"errno" => $errno,
|
||||
"errstr" => $errstr);
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": $errstr ($errno)" . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// SMTP server can take longer to respond, give longer timeout for first read
|
||||
// Windows does not have support for this timeout function
|
||||
if(substr(PHP_OS, 0, 3) != "WIN")
|
||||
socket_set_timeout($this->smtp_conn, $tval, 0);
|
||||
|
||||
// get any announcement
|
||||
$announce = $this->get_lines();
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $announce . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate a TLS communication with the server.
|
||||
*
|
||||
* SMTP CODE 220 Ready to start TLS
|
||||
* SMTP CODE 501 Syntax error (no parameters allowed)
|
||||
* SMTP CODE 454 TLS not available due to temporary reason
|
||||
* @access public
|
||||
* @return bool success
|
||||
*/
|
||||
public function StartTLS() {
|
||||
$this->error = null; # to avoid confusion
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array("error" => "Called StartTLS() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($this->smtp_conn,"STARTTLS" . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 220) {
|
||||
$this->error =
|
||||
array("error" => "STARTTLS not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Begin encrypted connection
|
||||
if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs SMTP authentication. Must be run after running the
|
||||
* Hello() method. Returns true if successfully authenticated.
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Authenticate($username, $password) {
|
||||
// Start authentication
|
||||
fputs($this->smtp_conn,"AUTH LOGIN" . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($code != 334) {
|
||||
$this->error =
|
||||
array("error" => "AUTH not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send encoded username
|
||||
fputs($this->smtp_conn, base64_encode($username) . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($code != 334) {
|
||||
$this->error =
|
||||
array("error" => "Username not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send encoded password
|
||||
fputs($this->smtp_conn, base64_encode($password) . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($code != 235) {
|
||||
$this->error =
|
||||
array("error" => "Password not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if connected to a server otherwise false
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Connected() {
|
||||
if(!empty($this->smtp_conn)) {
|
||||
$sock_status = socket_get_status($this->smtp_conn);
|
||||
if($sock_status["eof"]) {
|
||||
// the socket is valid but we are not connected
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> NOTICE:" . $this->CRLF . "EOF caught while checking if connected";
|
||||
}
|
||||
$this->Close();
|
||||
return false;
|
||||
}
|
||||
return true; // everything looks good
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the socket and cleans up the state of the class.
|
||||
* It is not considered good to use this function without
|
||||
* first trying to use QUIT.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function Close() {
|
||||
$this->error = null; // so there is no confusion
|
||||
$this->helo_rply = null;
|
||||
if(!empty($this->smtp_conn)) {
|
||||
// close the connection and cleanup
|
||||
fclose($this->smtp_conn);
|
||||
$this->smtp_conn = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// SMTP COMMANDS
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Issues a data command and sends the msg_data to the server
|
||||
* finializing the mail transaction. $msg_data is the message
|
||||
* that is to be send with the headers. Each header needs to be
|
||||
* on a single line followed by a <CRLF> with the message headers
|
||||
* and the message body being seperated by and additional <CRLF>.
|
||||
*
|
||||
* Implements rfc 821: DATA <CRLF>
|
||||
*
|
||||
* SMTP CODE INTERMEDIATE: 354
|
||||
* [data]
|
||||
* <CRLF>.<CRLF>
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE FAILURE: 552,554,451,452
|
||||
* SMTP CODE FAILURE: 451,554
|
||||
* SMTP CODE ERROR : 500,501,503,421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Data($msg_data) {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Data() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($this->smtp_conn,"DATA" . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 354) {
|
||||
$this->error =
|
||||
array("error" => "DATA command not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* the server is ready to accept data!
|
||||
* according to rfc 821 we should not send more than 1000
|
||||
* including the CRLF
|
||||
* characters on a single line so we will break the data up
|
||||
* into lines by \r and/or \n then if needed we will break
|
||||
* each of those into smaller lines to fit within the limit.
|
||||
* in addition we will be looking for lines that start with
|
||||
* a period '.' and append and additional period '.' to that
|
||||
* line. NOTE: this does not count towards limit.
|
||||
*/
|
||||
|
||||
// normalize the line breaks so we know the explode works
|
||||
$msg_data = str_replace("\r\n","\n",$msg_data);
|
||||
$msg_data = str_replace("\r","\n",$msg_data);
|
||||
$lines = explode("\n",$msg_data);
|
||||
|
||||
/* we need to find a good way to determine is headers are
|
||||
* in the msg_data or if it is a straight msg body
|
||||
* currently I am assuming rfc 822 definitions of msg headers
|
||||
* and if the first field of the first line (':' sperated)
|
||||
* does not contain a space then it _should_ be a header
|
||||
* and we can process all lines before a blank "" line as
|
||||
* headers.
|
||||
*/
|
||||
|
||||
$field = substr($lines[0],0,strpos($lines[0],":"));
|
||||
$in_headers = false;
|
||||
if(!empty($field) && !strstr($field," ")) {
|
||||
$in_headers = true;
|
||||
}
|
||||
|
||||
$max_line_length = 998; // used below; set here for ease in change
|
||||
|
||||
while(list(,$line) = @each($lines)) {
|
||||
$lines_out = null;
|
||||
if($line == "" && $in_headers) {
|
||||
$in_headers = false;
|
||||
}
|
||||
// ok we need to break this line up into several smaller lines
|
||||
while(strlen($line) > $max_line_length) {
|
||||
$pos = strrpos(substr($line,0,$max_line_length)," ");
|
||||
|
||||
// Patch to fix DOS attack
|
||||
if(!$pos) {
|
||||
$pos = $max_line_length - 1;
|
||||
$lines_out[] = substr($line,0,$pos);
|
||||
$line = substr($line,$pos);
|
||||
} else {
|
||||
$lines_out[] = substr($line,0,$pos);
|
||||
$line = substr($line,$pos + 1);
|
||||
}
|
||||
|
||||
/* if processing headers add a LWSP-char to the front of new line
|
||||
* rfc 822 on long msg headers
|
||||
*/
|
||||
if($in_headers) {
|
||||
$line = "\t" . $line;
|
||||
}
|
||||
}
|
||||
$lines_out[] = $line;
|
||||
|
||||
// send the lines to the server
|
||||
while(list(,$line_out) = @each($lines_out)) {
|
||||
if(strlen($line_out) > 0)
|
||||
{
|
||||
if(substr($line_out, 0, 1) == ".") {
|
||||
$line_out = "." . $line_out;
|
||||
}
|
||||
}
|
||||
fputs($this->smtp_conn,$line_out . $this->CRLF);
|
||||
}
|
||||
}
|
||||
|
||||
// message data has been sent
|
||||
fputs($this->smtp_conn, $this->CRLF . "." . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250) {
|
||||
$this->error =
|
||||
array("error" => "DATA not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the HELO command to the smtp server.
|
||||
* This makes sure that we and the server are in
|
||||
* the same known state.
|
||||
*
|
||||
* Implements from rfc 821: HELO <SP> <domain> <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE ERROR : 500, 501, 504, 421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Hello($host = '') {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Hello() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
// if hostname for HELO was not specified send default
|
||||
if(empty($host)) {
|
||||
// determine appropriate default to send to server
|
||||
$host = "localhost";
|
||||
}
|
||||
|
||||
// Send extended hello first (RFC 2821)
|
||||
if(!$this->SendHello("EHLO", $host)) {
|
||||
if(!$this->SendHello("HELO", $host)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a HELO/EHLO command.
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function SendHello($hello, $host) {
|
||||
fputs($this->smtp_conn, $hello . " " . $host . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER: " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250) {
|
||||
$this->error =
|
||||
array("error" => $hello . " not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->helo_rply = $rply;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a mail transaction from the email address specified in
|
||||
* $from. Returns true if successful or false otherwise. If True
|
||||
* the mail transaction is started and then one or more Recipient
|
||||
* commands may be called followed by a Data command.
|
||||
*
|
||||
* Implements rfc 821: MAIL <SP> FROM:<reverse-path> <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE SUCCESS: 552,451,452
|
||||
* SMTP CODE SUCCESS: 500,501,421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Mail($from) {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Mail() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
$useVerp = ($this->do_verp ? "XVERP" : "");
|
||||
fputs($this->smtp_conn,"MAIL FROM:<" . $from . ">" . $useVerp . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250) {
|
||||
$this->error =
|
||||
array("error" => "MAIL not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the quit command to the server and then closes the socket
|
||||
* if there is no error or the $close_on_error argument is true.
|
||||
*
|
||||
* Implements from rfc 821: QUIT <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 221
|
||||
* SMTP CODE ERROR : 500
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Quit($close_on_error = true) {
|
||||
$this->error = null; // so there is no confusion
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Quit() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
// send the quit command to the server
|
||||
fputs($this->smtp_conn,"quit" . $this->CRLF);
|
||||
|
||||
// get any good-bye messages
|
||||
$byemsg = $this->get_lines();
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $byemsg . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
$rval = true;
|
||||
$e = null;
|
||||
|
||||
$code = substr($byemsg,0,3);
|
||||
if($code != 221) {
|
||||
// use e as a tmp var cause Close will overwrite $this->error
|
||||
$e = array("error" => "SMTP server rejected quit command",
|
||||
"smtp_code" => $code,
|
||||
"smtp_rply" => substr($byemsg,4));
|
||||
$rval = false;
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $e["error"] . ": " . $byemsg . $this->CRLF . '<br />';
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($e) || $close_on_error) {
|
||||
$this->Close();
|
||||
}
|
||||
|
||||
return $rval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the command RCPT to the SMTP server with the TO: argument of $to.
|
||||
* Returns true if the recipient was accepted false if it was rejected.
|
||||
*
|
||||
* Implements from rfc 821: RCPT <SP> TO:<forward-path> <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250,251
|
||||
* SMTP CODE FAILURE: 550,551,552,553,450,451,452
|
||||
* SMTP CODE ERROR : 500,501,503,421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Recipient($to) {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Recipient() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($this->smtp_conn,"RCPT TO:<" . $to . ">" . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250 && $code != 251) {
|
||||
$this->error =
|
||||
array("error" => "RCPT not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the RSET command to abort and transaction that is
|
||||
* currently in progress. Returns true if successful false
|
||||
* otherwise.
|
||||
*
|
||||
* Implements rfc 821: RSET <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE ERROR : 500,501,504,421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Reset() {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called Reset() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($this->smtp_conn,"RSET" . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250) {
|
||||
$this->error =
|
||||
array("error" => "RSET failed",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a mail transaction from the email address specified in
|
||||
* $from. Returns true if successful or false otherwise. If True
|
||||
* the mail transaction is started and then one or more Recipient
|
||||
* commands may be called followed by a Data command. This command
|
||||
* will send the message to the users terminal if they are logged
|
||||
* in and send them an email.
|
||||
*
|
||||
* Implements rfc 821: SAML <SP> FROM:<reverse-path> <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE SUCCESS: 552,451,452
|
||||
* SMTP CODE SUCCESS: 500,501,502,421
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function SendAndMail($from) {
|
||||
$this->error = null; // so no confusion is caused
|
||||
|
||||
if(!$this->connected()) {
|
||||
$this->error = array(
|
||||
"error" => "Called SendAndMail() without being connected");
|
||||
return false;
|
||||
}
|
||||
|
||||
fputs($this->smtp_conn,"SAML FROM:" . $from . $this->CRLF);
|
||||
|
||||
$rply = $this->get_lines();
|
||||
$code = substr($rply,0,3);
|
||||
|
||||
if($this->do_debug >= 2) {
|
||||
echo "SMTP -> FROM SERVER:" . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
|
||||
if($code != 250) {
|
||||
$this->error =
|
||||
array("error" => "SAML not accepted from server",
|
||||
"smtp_code" => $code,
|
||||
"smtp_msg" => substr($rply,4));
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an optional command for SMTP that this class does not
|
||||
* support. This method is here to make the RFC821 Definition
|
||||
* complete for this class and __may__ be implimented in the future
|
||||
*
|
||||
* Implements from rfc 821: TURN <CRLF>
|
||||
*
|
||||
* SMTP CODE SUCCESS: 250
|
||||
* SMTP CODE FAILURE: 502
|
||||
* SMTP CODE ERROR : 500, 503
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function Turn() {
|
||||
$this->error = array("error" => "This method, TURN, of the SMTP ".
|
||||
"is not implemented");
|
||||
if($this->do_debug >= 1) {
|
||||
echo "SMTP -> NOTICE: " . $this->error["error"] . $this->CRLF . '<br />';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current error
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getError() {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////
|
||||
// INTERNAL FUNCTIONS
|
||||
/////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Read in as many lines as possible
|
||||
* either before eof or socket timeout occurs on the operation.
|
||||
* With SMTP we can tell if we have more lines to read if the
|
||||
* 4th character is '-' symbol. If it is a space then we don't
|
||||
* need to read anything else.
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
private function get_lines() {
|
||||
$data = "";
|
||||
while($str = @fgets($this->smtp_conn,515)) {
|
||||
if($this->do_debug >= 4) {
|
||||
echo "SMTP -> get_lines(): \$data was \"$data\"" . $this->CRLF . '<br />';
|
||||
echo "SMTP -> get_lines(): \$str is \"$str\"" . $this->CRLF . '<br />';
|
||||
}
|
||||
$data .= $str;
|
||||
if($this->do_debug >= 4) {
|
||||
echo "SMTP -> get_lines(): \$data is \"$data\"" . $this->CRLF . '<br />';
|
||||
}
|
||||
// if 4th character is a space, we are done reading, break the loop
|
||||
if(substr($str,3,1) == " ") { break; }
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/* *
|
||||
* 支付宝接口公用函数
|
||||
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
|
||||
* 版本:3.3
|
||||
* 日期:2012-07-19
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
* @param $para 需要拼接的数组
|
||||
* return 拼接完成以后的字符串
|
||||
*/
|
||||
function createLinkstring($para) {
|
||||
$arg = "";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$arg.=$key."=".$val."&";
|
||||
}
|
||||
//去掉最后一个&字符
|
||||
$arg = substr($arg,0,count($arg)-2);
|
||||
|
||||
//如果存在转义字符,那么去掉转义
|
||||
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
/**
|
||||
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
|
||||
* @param $para 需要拼接的数组
|
||||
* return 拼接完成以后的字符串
|
||||
*/
|
||||
function createLinkstringUrlencode($para) {
|
||||
$arg = "";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$arg.=$key."=".urlencode($val)."&";
|
||||
}
|
||||
//去掉最后一个&字符
|
||||
$arg = substr($arg,0,count($arg)-2);
|
||||
|
||||
//如果存在转义字符,那么去掉转义
|
||||
if(get_magic_quotes_gpc()){$arg = stripslashes($arg);}
|
||||
|
||||
return $arg;
|
||||
}
|
||||
/**
|
||||
* 除去数组中的空值和签名参数
|
||||
* @param $para 签名参数组
|
||||
* return 去掉空值与签名参数后的新签名参数组
|
||||
*/
|
||||
function paraFilter($para) {
|
||||
$para_filter = array();
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
if($key == "sign" || $key == "sign_type" || $val == "")continue;
|
||||
else $para_filter[$key] = $para[$key];
|
||||
}
|
||||
return $para_filter;
|
||||
}
|
||||
/**
|
||||
* 对数组排序
|
||||
* @param $para 排序前的数组
|
||||
* return 排序后的数组
|
||||
*/
|
||||
function argSort($para) {
|
||||
ksort($para);
|
||||
reset($para);
|
||||
return $para;
|
||||
}
|
||||
/**
|
||||
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
|
||||
* 注意:服务器需要开通fopen配置
|
||||
* @param $word 要写入日志里的文本内容 默认值:空值
|
||||
*/
|
||||
function logResult($word='') {
|
||||
$fp = fopen("log.txt","a");
|
||||
flock($fp, LOCK_EX) ;
|
||||
fwrite($fp,"执行日期:".strftime("%Y%m%d%H%M%S",time())."\n".$word."\n");
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程获取数据,POST模式
|
||||
* 注意:
|
||||
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
|
||||
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
|
||||
* @param $url 指定URL完整路径地址
|
||||
* @param $cacert_url 指定当前工作目录绝对路径
|
||||
* @param $para 请求的数据
|
||||
* @param $input_charset 编码格式。默认值:空值
|
||||
* return 远程输出的数据
|
||||
*/
|
||||
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') {
|
||||
|
||||
if (trim($input_charset) != '') {
|
||||
$url = $url."_input_charset=".$input_charset;
|
||||
}
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
|
||||
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
|
||||
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
|
||||
curl_setopt($curl,CURLOPT_POST,true); // post传输数据
|
||||
curl_setopt($curl,CURLOPT_POSTFIELDS,$para);// post传输数据
|
||||
$responseText = curl_exec($curl);
|
||||
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
|
||||
curl_close($curl);
|
||||
|
||||
return $responseText;
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程获取数据,GET模式
|
||||
* 注意:
|
||||
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
|
||||
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
|
||||
* @param $url 指定URL完整路径地址
|
||||
* @param $cacert_url 指定当前工作目录绝对路径
|
||||
* return 远程输出的数据
|
||||
*/
|
||||
function getHttpResponseGET($url,$cacert_url) {
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0 ); // 过滤HTTP头
|
||||
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1);// 显示输出结果
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL证书认证
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//严格认证
|
||||
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//证书地址
|
||||
$responseText = curl_exec($curl);
|
||||
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
|
||||
curl_close($curl);
|
||||
|
||||
return $responseText;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实现多种字符编码方式
|
||||
* @param $input 需要编码的字符串
|
||||
* @param $_output_charset 输出的编码格式
|
||||
* @param $_input_charset 输入的编码格式
|
||||
* return 编码后的字符串
|
||||
*/
|
||||
function charsetEncode($input,$_output_charset ,$_input_charset) {
|
||||
$output = "";
|
||||
if(!isset($_output_charset) )$_output_charset = $_input_charset;
|
||||
if($_input_charset == $_output_charset || $input ==null ) {
|
||||
$output = $input;
|
||||
} elseif (function_exists("mb_convert_encoding")) {
|
||||
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
|
||||
} elseif(function_exists("iconv")) {
|
||||
$output = iconv($_input_charset,$_output_charset,$input);
|
||||
} else die("sorry, you have no libs support for charset change.");
|
||||
return $output;
|
||||
}
|
||||
/**
|
||||
* 实现多种字符解码方式
|
||||
* @param $input 需要解码的字符串
|
||||
* @param $_output_charset 输出的解码格式
|
||||
* @param $_input_charset 输入的解码格式
|
||||
* return 解码后的字符串
|
||||
*/
|
||||
function charsetDecode($input,$_input_charset ,$_output_charset) {
|
||||
$output = "";
|
||||
if(!isset($_input_charset) )$_input_charset = $_input_charset ;
|
||||
if($_input_charset == $_output_charset || $input ==null ) {
|
||||
$output = $input;
|
||||
} elseif (function_exists("mb_convert_encoding")) {
|
||||
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);
|
||||
} elseif(function_exists("iconv")) {
|
||||
$output = iconv($_input_charset,$_output_charset,$input);
|
||||
} else die("sorry, you have no libs support for charset changes.");
|
||||
return $output;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/* *
|
||||
* MD5
|
||||
* 详细:MD5加密
|
||||
* 版本:3.3
|
||||
* 日期:2012-07-19
|
||||
* 说明:
|
||||
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
|
||||
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
|
||||
*/
|
||||
|
||||
/**
|
||||
* 签名字符串
|
||||
* @param $prestr 需要签名的字符串
|
||||
* @param $key 私钥
|
||||
* return 签名结果
|
||||
*/
|
||||
function md5Sign($prestr, $key) {
|
||||
$prestr = $prestr . $key;
|
||||
return md5($prestr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名
|
||||
* @param $prestr 需要签名的字符串
|
||||
* @param $sign 签名结果
|
||||
* @param $key 私钥
|
||||
* return 签名结果
|
||||
*/
|
||||
function md5Verify($prestr, $sign, $key) {
|
||||
$prestr = $prestr . $key;
|
||||
$mysgin = md5($prestr);
|
||||
|
||||
if($mysgin == $sign) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/* *
|
||||
* 类名:EpayNotify
|
||||
* 功能:木皆支付通知处理类
|
||||
* 详细:处理易支付接口通知返回
|
||||
*/
|
||||
|
||||
require_once("epay_core.function.php");
|
||||
require_once("epay_md5.function.php");
|
||||
|
||||
class AlipayNotify {
|
||||
|
||||
var $alipay_config;
|
||||
|
||||
function __construct($alipay_config){
|
||||
$this->alipay_config = $alipay_config;
|
||||
$this->http_verify_url = $this->alipay_config['apiurl'].'api.php?';
|
||||
}
|
||||
function AlipayNotify($alipay_config) {
|
||||
$this->__construct($alipay_config);
|
||||
}
|
||||
/**
|
||||
* 针对notify_url验证消息是否是支付宝发出的合法消息
|
||||
* @return 验证结果
|
||||
*/
|
||||
function verifyNotify(){
|
||||
if(empty($_GET)) {//判断POST来的数组是否为空
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
//生成签名结果
|
||||
$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
|
||||
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
|
||||
$responseTxt = 'true';
|
||||
//if (! empty($_POST["notify_id"])) {$responseTxt = $this->getResponse($_POST["notify_id"]);}
|
||||
|
||||
//验证
|
||||
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
|
||||
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
|
||||
if (preg_match("/true$/i",$responseTxt) && $isSign) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对return_url验证消息是否是支付宝发出的合法消息
|
||||
* @return 验证结果
|
||||
*/
|
||||
function verifyReturn(){
|
||||
if(empty($_GET)) {//判断POST来的数组是否为空
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
//生成签名结果
|
||||
$isSign = $this->getSignVeryfy($_GET, $_GET["sign"]);
|
||||
//获取支付宝远程服务器ATN结果(验证是否是支付宝发来的消息)
|
||||
$responseTxt = 'true';
|
||||
//if (! empty($_GET["notify_id"])) {$responseTxt = $this->getResponse($_GET["notify_id"]);}
|
||||
|
||||
//验证
|
||||
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
|
||||
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
|
||||
if (preg_match("/true$/i",$responseTxt) && $isSign) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取返回时的签名验证结果
|
||||
* @param $para_temp 通知返回来的参数数组
|
||||
* @param $sign 返回的签名结果
|
||||
* @return 签名验证结果
|
||||
*/
|
||||
function getSignVeryfy($para_temp, $sign) {
|
||||
//除去待签名参数数组中的空值和签名参数
|
||||
$para_filter = paraFilter($para_temp);
|
||||
|
||||
//对待签名参数数组排序
|
||||
$para_sort = argSort($para_filter);
|
||||
|
||||
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
$prestr = createLinkstring($para_sort);
|
||||
|
||||
$isSgin = false;
|
||||
$isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']);
|
||||
|
||||
return $isSgin;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程服务器ATN结果,验证返回URL
|
||||
* @param $notify_id 通知校验ID
|
||||
* @return 服务器ATN结果
|
||||
* 验证结果集:
|
||||
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
|
||||
* true 返回正确信息
|
||||
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
|
||||
*/
|
||||
function getResponse($notify_id) {
|
||||
$transport = strtolower(trim($this->alipay_config['transport']));
|
||||
$partner = trim($this->alipay_config['partner']);
|
||||
$veryfy_url = '';
|
||||
if($transport == 'https') {
|
||||
$veryfy_url = $this->https_verify_url;
|
||||
}
|
||||
else {
|
||||
$veryfy_url = $this->http_verify_url;
|
||||
}
|
||||
$veryfy_url = $veryfy_url."partner=" . $partner . "¬ify_id=" . $notify_id;
|
||||
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
|
||||
|
||||
return $responseTxt;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
/* *
|
||||
* 类名:EpaySubmit
|
||||
* 功能:木皆支付接口请求提交类
|
||||
* 详细:构造易支付接口表单HTML文本,获取远程HTTP数据
|
||||
*/
|
||||
require_once("epay_core.function.php");
|
||||
require_once("epay_md5.function.php");
|
||||
|
||||
class AlipaySubmit {
|
||||
|
||||
var $alipay_config;
|
||||
|
||||
function __construct($alipay_config){
|
||||
$this->alipay_config = $alipay_config;
|
||||
$this->alipay_gateway_new = $this->alipay_config['apiurl'].'submit.php?';
|
||||
}
|
||||
function AlipaySubmit($alipay_config) {
|
||||
$this->__construct($alipay_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名结果
|
||||
* @param $para_sort 已排序要签名的数组
|
||||
* return 签名结果字符串
|
||||
*/
|
||||
function buildRequestMysign($para_sort) {
|
||||
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
|
||||
$prestr = createLinkstring($para_sort);
|
||||
|
||||
$mysign = md5Sign($prestr, $this->alipay_config['key']);
|
||||
|
||||
return $mysign;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成要请求给支付宝的参数数组
|
||||
* @param $para_temp 请求前的参数数组
|
||||
* @return 要请求的参数数组
|
||||
*/
|
||||
function buildRequestPara($para_temp) {
|
||||
//除去待签名参数数组中的空值和签名参数
|
||||
$para_filter = paraFilter($para_temp);
|
||||
|
||||
//对待签名参数数组排序
|
||||
$para_sort = argSort($para_filter);
|
||||
|
||||
//生成签名结果
|
||||
$mysign = $this->buildRequestMysign($para_sort);
|
||||
|
||||
//签名结果与签名方式加入请求提交参数组中
|
||||
$para_sort['sign'] = $mysign;
|
||||
$para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type']));
|
||||
|
||||
return $para_sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成要请求给支付宝的参数数组
|
||||
* @param $para_temp 请求前的参数数组
|
||||
* @return 要请求的参数数组字符串
|
||||
*/
|
||||
function buildRequestParaToString($para_temp) {
|
||||
//待请求参数数组
|
||||
$para = $this->buildRequestPara($para_temp);
|
||||
|
||||
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
|
||||
$request_data = createLinkstringUrlencode($para);
|
||||
|
||||
return $request_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立请求,以表单HTML形式构造(默认)
|
||||
* @param $para_temp 请求参数数组
|
||||
* @param $method 提交方式。两个值可选:post、get
|
||||
* @param $button_name 确认按钮显示文字
|
||||
* @return 提交表单HTML文本
|
||||
*/
|
||||
function buildRequestForm($para_temp, $method='POST', $button_name='正在跳转') {
|
||||
//待请求参数数组
|
||||
$para = $this->buildRequestPara($para_temp);
|
||||
|
||||
$sHtml = "<form id='alipaysubmit' name='alipaysubmit' action='".$this->alipay_gateway_new."_input_charset=".trim(strtolower($this->alipay_config['input_charset']))."' method='".$method."'>";
|
||||
while (list ($key, $val) = each ($para)) {
|
||||
$sHtml.= "<input type='hidden' name='".$key."' value='".$val."'/>";
|
||||
}
|
||||
|
||||
//submit按钮控件请不要含有name属性
|
||||
$sHtml = $sHtml."<input type='submit' value='".$button_name."'></form>";
|
||||
|
||||
$sHtml = $sHtml."<script>document.forms['alipaysubmit'].submit();</script>";
|
||||
|
||||
return $sHtml;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
$t_url = (($_SERVER['SERVER_PORT']==443) ? 'https':'http').'://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'],(substr($_SERVER['DOCUMENT_ROOT'],-1) == '/') ? '/':'',dirname($_SERVER['SCRIPT_FILENAME']));
|
||||
if($t_url == ''){
|
||||
include("./template/eruyi/error.html");//环境不合适
|
||||
return;
|
||||
}else{
|
||||
if(file_exists('./install/upgrade.php')){//需要升级
|
||||
header("Location: " .$t_url ."/install/upgrade.php");
|
||||
return;
|
||||
}
|
||||
if(file_exists('./install/install.lock')==false){//需要安装
|
||||
header("Location: " .$t_url ."/install");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
require("include/global.php");
|
||||
$app_res = Db::table('app','as A')->field('A.id,A.name,A.state,A.app_bb,IFNULL(U.us,0) as unum')->JOIN("(SELECT appid,COUNT(*) AS us FROM {$DP}user GROUP BY appid) AS U",'A.id=U.appid')->where('A.state',"y")->select();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
define('APP_DEBUG',0);//错误输出,0=关闭,1=开启
|
||||
|
||||
define('DEFAULT_RETURN_TYPE',0);//默认输出0=JSON格式,1=xml格式
|
||||
|
||||
define('USER_TOKEN_TIME',1800);// 用户状态在线有效期
|
||||
|
||||
define('DATA_PAGE_ENUMS',10);// 每页显示数据
|
||||
|
||||
define('DEFAULT_TIMEZONE','PRC');// 默认时区
|
||||
|
||||
define('INDEX_TEMPLATE','default');//首页模板
|
||||
|
||||
define('API_EXTEND_MULU','extend/api/');//api扩展目录
|
||||
|
||||
define('ADM_EXTEND_MULU','extend/adm/');//adm扩展目录
|
||||
|
||||
define('USER_PIC_MULU','data/pic/');//用户头像目录
|
||||
|
||||
define('ADM_LOG',1);//管理日志,0=关闭,1=开启
|
||||
|
||||
define('USER_LOG',1);//用户日志,0=关闭,1=开启
|
||||
|
||||
define('LOG_DEL',30);//日志删除时间
|
||||
|
||||
define('LOG_KEY','SbwxrbTMMiyQBrHC3zmTcEr7Js3p5nBJ');//日志KEY
|
||||
|
||||
define('FCPATH', str_replace("\\",'/', dirname(dirname(__FILE__)).'/')); // 网站根目录
|
||||
|
||||
define('WEB_URL',(($_SERVER['SERVER_PORT']==443) ? 'https':'http').'://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'],(substr($_SERVER['DOCUMENT_ROOT'],-1) == '/') ? '/':'',dirname($_SERVER['SCRIPT_FILENAME']))); // 网站根目录
|
||||
|
||||
define('EDITION', 1.71); // 当前系统版本
|
||||
?>
|
||||
@@ -0,0 +1,800 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* File:MySQL数据库操作类
|
||||
* Author:易如意
|
||||
* QQ:51154393
|
||||
* Url:www.eruyi.cn
|
||||
*/
|
||||
require_once 'db.config.php';
|
||||
|
||||
class Db{
|
||||
|
||||
|
||||
//1.私有的静态属性
|
||||
private static $link;
|
||||
private $table_name;
|
||||
private $objdb;
|
||||
private $options;
|
||||
|
||||
private function __construct() {
|
||||
|
||||
if (!$this->objdb = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWD)) {
|
||||
switch ($this->geterrno()) {
|
||||
case 2005:
|
||||
exit("连接数据库失败,数据库地址错误或者数据库服务器不可用");
|
||||
break;
|
||||
case 2003:
|
||||
exit("连接数据库失败,数据库端口错误");
|
||||
break;
|
||||
case 2006:
|
||||
exit("连接数据库失败,数据库服务器不可用");
|
||||
break;
|
||||
case 1045:
|
||||
exit("连接数据库失败,数据库用户名或密码错误");
|
||||
break;
|
||||
default :
|
||||
exit("连接数据库失败,请检查数据库信息。错误编号:" . $this->geterrno());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($this->getMysqlVersion() > '4.1') {
|
||||
mysqli_query($this->objdb,"SET NAMES 'utf8'");
|
||||
}
|
||||
@mysqli_select_db($this->objdb,DB_NAME) OR exit("连接数据库失败,未找到您填写的数据库");
|
||||
}
|
||||
|
||||
|
||||
|
||||
//静态公共接口
|
||||
public static function getInstance(){
|
||||
if(!(self::$link instanceof self)){
|
||||
self::$link = new self();
|
||||
}
|
||||
return self::$link;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取mysql错误
|
||||
*/
|
||||
function geterror() {
|
||||
return mysqli_error($this->objdb);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取得数据库版本信息
|
||||
*/
|
||||
function getMysqlVersion() {
|
||||
return mysqli_get_server_info($this->objdb);
|
||||
}
|
||||
/**
|
||||
* 获取mysql错误编码
|
||||
*/
|
||||
function geterrno() {
|
||||
return mysqli_connect_errno($this->objdb);
|
||||
}
|
||||
|
||||
//返回数据库实例对象
|
||||
public static function table($table_name,$val=FALSE){
|
||||
$link = self::getInstance();
|
||||
if(!defined('DB_PRE') or DB_PRE == ''){
|
||||
if($val){
|
||||
$link->table_name = "`$table_name` $val";
|
||||
}else{
|
||||
$link->table_name = "`$table_name`";
|
||||
}
|
||||
}else{
|
||||
if($val){
|
||||
$link->table_name = "`".DB_PRE."$table_name` $val";
|
||||
}else{
|
||||
$link->table_name = "`".DB_PRE."$table_name`";
|
||||
}
|
||||
}
|
||||
return $link;
|
||||
}
|
||||
|
||||
|
||||
//field:格式->('id,name,time......')
|
||||
public function field($field){
|
||||
$this->options['field'] = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//处理field数据,组sql
|
||||
public function deal_field($field){
|
||||
$field = $field['field'];
|
||||
return $field;
|
||||
}
|
||||
|
||||
|
||||
//设置where条件(数组和多个where都可以),where('id',12) 或者 where([id=>12])
|
||||
public function where($key,$factor=null,$val=null){
|
||||
if($key != null && $factor != null && is_array($val)){//属于三者都有的情况,中间的参数就是条件
|
||||
if(is_string($key) && is_string($factor)){
|
||||
$v_str = "`$key` $factor ";
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
$count_val = count($val);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($val as $k=>$v){
|
||||
if($count_val == $nums){
|
||||
$str .= "'$v'";
|
||||
}else{
|
||||
$str .= "'$v'".' '.'and'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $v_str.$str;
|
||||
}elseif($key != null && $factor != null && $val != null && !is_array($val)){
|
||||
$v = (string)$val;
|
||||
if(is_string($key) && is_string($factor) && is_string($v)){
|
||||
if($factor == 'in'){
|
||||
$v_str = "$key $factor $val";
|
||||
}else{
|
||||
$v_str = "$key $factor '$val'";
|
||||
}
|
||||
}elseif(is_array($key) && is_string($factor) && is_string($val)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
$str .= "$k ='$v'";
|
||||
}else{
|
||||
$str .= "$k ='$v'".' '.'and'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $factor.$str.$val;
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
}else{//两个或者一个参数的情况
|
||||
$v = (string)$val;
|
||||
$val = (string)$factor;//此种情况将第二参数传给第三个参数
|
||||
if(is_string($key) && !is_array($key)){//为字符串
|
||||
$v_str = "$key = '$val'";
|
||||
}else if(is_array($key)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
$str .= "$k ='$v'";
|
||||
}else{
|
||||
$str .= "$k ='$v'".' '.'and'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $str;
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
}
|
||||
$this->options['where'][] = $v_str;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//处理where数据,组sql
|
||||
public function deal_where($where){
|
||||
$arr = $where['where'];
|
||||
$count_key = count($arr);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($arr as $key=>$val){
|
||||
if($count_key == $nums){
|
||||
$str .= $val;
|
||||
}else{
|
||||
$str .= $val.' '.'and'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
return 'where '.$str;
|
||||
}
|
||||
|
||||
|
||||
//设置orwhere条件(数组和多个where都可以),where('id',12) 或者 where([id=>12])
|
||||
public function whereOr($key,$factor='',$val=''){
|
||||
$v = (string)$val;
|
||||
if($key != '' && $factor != '' && $v != ''){//属于三者都有的情况,中间的参数就是条件
|
||||
if(is_string($key) && is_string($factor) && is_string($v)){
|
||||
$v_str = "$key $factor '$val'";
|
||||
}elseif(is_array($key) && is_string($factor) && is_string($v)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
$str .= "$k = '$v'";
|
||||
}else{
|
||||
$str .= "$k = '$v'".' '.'or'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $factor.$str.$val;
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
}else{//两个或者一个参数的情况
|
||||
$val = (string)$factor;//此种情况将第二参数传给第三个参数
|
||||
if(is_string($key) && !is_array($key)){//为字符串
|
||||
$v_str = "$key ='$val'";
|
||||
}else if(is_array($key) && !empty($val)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
$str .= "$k = '$v'";
|
||||
}else{
|
||||
$str .= "$k = '$v'".' '.'or'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $str.$val;
|
||||
}else if(is_array($key) && empty($val)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
$str .= "$k = '$v'";
|
||||
}else{
|
||||
$str .= "$k = '$v'".' '.'or'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $str;
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
}
|
||||
$this->options['whereOr'][] = $v_str;
|
||||
return $this;
|
||||
}
|
||||
|
||||
//处理orwhere数据,组sql
|
||||
public function deal_whereOr($whereOr){
|
||||
$arr = $whereOr['whereOr'];
|
||||
$count_key = count($arr);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($arr as $key=>$val){
|
||||
if($count_key == $nums){
|
||||
$str .= $val;
|
||||
}else{
|
||||
$str .= $val.' '.'or'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
return 'or '.$str;
|
||||
}
|
||||
|
||||
//设置JOIN条件(数组和多个JOIN都可以),JOIN('id',12) 或者 JOIN([id=>12])
|
||||
public function join($key=null,$factor='',$val=''){
|
||||
$v = (string)$val;
|
||||
if($key != '' && $factor != '' && $v != ''){//属于三者都有的情况,中间的参数就是条件
|
||||
if(is_string($key) && is_string($factor) && is_string($v)){
|
||||
if(!defined('DB_PRE') or DB_PRE == ''){
|
||||
$v_str = "`$key` $factor ON ($val)";
|
||||
}else{
|
||||
$v_str = "`".DB_PRE."$key` $factor ON ($val)";
|
||||
}
|
||||
}else{
|
||||
die("failed: ".'不合法');
|
||||
}
|
||||
}else{//两个或者一个参数的情况
|
||||
$val = (string)$factor;//此种情况将第二参数传给第三个参数
|
||||
if(is_string($key) && !is_array($key) && $val != '' ){
|
||||
if (strpos($key, " ")){
|
||||
$v_str = "$key ON ($val)";
|
||||
}else{
|
||||
if(!defined('DB_PRE') or DB_PRE == ''){
|
||||
$v_str = "`$key` ON ($val)";
|
||||
}else{
|
||||
$v_str = "`".DB_PRE."$key` ON ($val)";
|
||||
|
||||
}
|
||||
}
|
||||
}elseif(is_string($key) && !is_array($key) && $val == '' ){
|
||||
$v_str = "$key ";
|
||||
}else if(is_array($key)){
|
||||
$count_key = count($key);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($key as $k=>$v){
|
||||
if($count_key == $nums){
|
||||
if(!defined('DB_PRE') or DB_PRE == ''){
|
||||
$str .= "`$k` ON ($v)";
|
||||
}else{
|
||||
$str .= "`".DB_PRE."$k` ON ($v)";
|
||||
}
|
||||
}else{
|
||||
if(!defined('DB_PRE') or DB_PRE == ''){
|
||||
$str .= "`$k` ON ($v)".' '.'LEFT JOIN'.' ';
|
||||
}else{
|
||||
$str .= "`".DB_PRE."$k` ON ($v)".' '.'LEFT JOIN'.' ';
|
||||
}
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
$v_str = $str;
|
||||
}else{
|
||||
$v_str = '';
|
||||
}
|
||||
}
|
||||
$this->options['join'][] = $v_str;
|
||||
return $this;
|
||||
}
|
||||
//处理JOIN数据,组sql
|
||||
public function deal_join($join){
|
||||
$arr = $join['join'];
|
||||
$count_key = count($arr);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($arr as $key=>$val){
|
||||
if($count_key == $nums){
|
||||
$str .= $val;
|
||||
}else{
|
||||
$str .= $val.' '.'LEFT JOIN'.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
return 'LEFT JOIN '.$str;
|
||||
}
|
||||
|
||||
|
||||
//追加sql原生语句
|
||||
public function addto($val){
|
||||
$v_str = (string)$val;
|
||||
$this->options['addto'][] = $v_str;
|
||||
return $this;
|
||||
}
|
||||
//处理原生数据,组sql
|
||||
public function deal_addto($addto){
|
||||
$arr = $addto['addto'];
|
||||
$count_key = count($arr);
|
||||
$nums = 1;
|
||||
$str = '';
|
||||
foreach($arr as $key=>$val){
|
||||
if($count_key == $nums){
|
||||
$str .= $val;
|
||||
}else{
|
||||
$str .= $val.' ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$nums = 1;
|
||||
return $str;
|
||||
}
|
||||
|
||||
//设置排序 格式->('id desc,time aes') //ORDER BY ticketnum_id desc,project_id desc
|
||||
public function order($order){
|
||||
$this->options['order'] = $order;
|
||||
return $this;
|
||||
}
|
||||
//处理order数据,租sql
|
||||
public function deal_order($order){
|
||||
$order = $order['order'];
|
||||
return 'ORDER BY '.$order;
|
||||
}
|
||||
|
||||
|
||||
//设置分页查询、格式->('0,10')
|
||||
public function limit($limit,$nums=''){
|
||||
if((string)$nums == '' && (string)$limit != ''){
|
||||
$this->options['limit'] = '0'.','.(string)$limit;
|
||||
}else{
|
||||
$this->options['limit'] = (string)$limit.','.(string)$nums;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
//处理limit数据,租sql
|
||||
public function deal_limit($limit){
|
||||
$limit = $limit['limit'];
|
||||
return 'limit '.$limit;
|
||||
}
|
||||
|
||||
//判断表存在否
|
||||
public function exist($true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$sql = 'SELECT * from '.$table;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_exist($link,$sql);
|
||||
}
|
||||
//判断表存在否sql操作
|
||||
public function query_exist($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//查找单条
|
||||
public function find($true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$field = isset($array['field'])?$array['field']:'*';
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.$field.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_find($link,$sql);
|
||||
}
|
||||
//查找单条数据sql操作
|
||||
public function query_find($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$arr = [];
|
||||
if($result && mysqli_num_rows($result)>0){
|
||||
$arr = mysqli_fetch_assoc($result);
|
||||
}
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
//$this->close_db($link);
|
||||
return isset($arr)?$arr:false;
|
||||
}
|
||||
|
||||
|
||||
//查询多条
|
||||
public function select($true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$field = isset($array['field'])?$array['field']:'*';
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.$field.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_select($link,$sql);
|
||||
}
|
||||
//查找多条数据sql操作
|
||||
public function query_select($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
$arr = [];
|
||||
if($result && mysqli_num_rows($result)>0){
|
||||
while($row=mysqli_fetch_assoc($result)){
|
||||
$arr[] = $row;
|
||||
}
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
//$this->close_db($link);
|
||||
return $arr;
|
||||
}
|
||||
|
||||
//聚合查询-count
|
||||
public function count($true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.'count(*)'.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_count($link,$sql);
|
||||
}
|
||||
//聚合查询-count sql操作
|
||||
public function query_count($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$count_json = mysqli_fetch_assoc($result);
|
||||
$count = $count_json['count(*)'];
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
return (int)$count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//聚合查询-max
|
||||
public function max($max,$true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.'max('.$max.')'.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_max($link,$sql,$max);
|
||||
}
|
||||
//聚合查询-max sql操作
|
||||
public function query_max($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$count_json = mysqli_fetch_assoc($result);
|
||||
$str_arr = explode(' ', $sql);
|
||||
$key_str = $str_arr[1];
|
||||
$count = $count_json[$key_str];
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
return (int)$count;
|
||||
}
|
||||
|
||||
|
||||
//聚合查询-min
|
||||
public function min($min,$true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.'min('.$min.')'.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_min($link,$sql,$min);
|
||||
}
|
||||
//聚合查询-min sql操作
|
||||
public function query_min($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$count_json = mysqli_fetch_assoc($result);
|
||||
$str_arr = explode(' ', $sql);
|
||||
$key_str = $str_arr[1];
|
||||
$count = $count_json[$key_str];
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
return (int)$count;
|
||||
}
|
||||
|
||||
|
||||
//聚合查询-sum
|
||||
public function sum($sum,$true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.'sum('.$sum.')'.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_sum($link,$sql,$sum);
|
||||
}
|
||||
//聚合查询-sum sql操作
|
||||
public function query_sum($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$count_json = mysqli_fetch_assoc($result);
|
||||
$str_arr = explode(' ', $sql);
|
||||
$key_str = $str_arr[1];
|
||||
$count = $count_json[$key_str];
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
return (int)$count;
|
||||
}
|
||||
|
||||
|
||||
//聚合查询-avg
|
||||
public function avg($avg,$true=true){
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'SELECT '.'avg('.$avg.')'.' from '.$table.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_avg($link,$sql,$avg);
|
||||
}
|
||||
//聚合查询-avg sql操作
|
||||
public function query_avg($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result){
|
||||
$count_json = mysqli_fetch_assoc($result);
|
||||
$str_arr = explode(' ', $sql);
|
||||
$key_str = $str_arr[1];
|
||||
$count = $count_json[$key_str];
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}
|
||||
return (int)$count;
|
||||
}
|
||||
|
||||
//处理options,组成sql语句(公共函数)
|
||||
public function do_sql(){
|
||||
$array = $this->options;
|
||||
if(empty($array)){
|
||||
return [];
|
||||
}
|
||||
$this->options = [];//清除记录
|
||||
$data = []; $stra = ''; $strb = '';
|
||||
foreach ($array as $key => $val) {
|
||||
$deal_something = 'deal_'.$key;
|
||||
if($key == 'field'){
|
||||
$stra .= $this->$deal_something($array).' ';
|
||||
$data['field'] = $stra;
|
||||
}else{
|
||||
$strb .= $this->$deal_something($array).' ';
|
||||
$data['make'] = $strb;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
//添加插入数据 $add:数组(['xxx'=>'xxx','xxxx'=>'xxxx'])
|
||||
public function add($add,$true=true){
|
||||
if(!is_array($add)){
|
||||
return false;
|
||||
}
|
||||
$data = $this->deal_add($add);
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$sql = 'INSERT INTO '.$table.' '.$data['key'].' VALUES '.$data['val'];
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_add($link,$sql);
|
||||
}
|
||||
//添加插入数据 sql操作
|
||||
public function query_add($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
if($result && mysqli_affected_rows($link)>0){
|
||||
$res = mysqli_insert_id($link);
|
||||
//$this->close_db($link);
|
||||
return $res;
|
||||
}elseif(APP_DEBUG==1){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//处理add的数据,租sql
|
||||
public function deal_add($add){
|
||||
$nums = 1;
|
||||
$counts = count($add);
|
||||
$stra = ''; $strb = '';
|
||||
foreach($add as $key=>$val){
|
||||
if($nums == 1){
|
||||
$stra .= '(`'.(string)$key.'`';
|
||||
$strb .= '('.(string)"'$val'";
|
||||
}elseif($nums == $counts){
|
||||
$stra .= ',`'.(string)$key.'`)';
|
||||
$strb .= ','.(string)"'$val'".')';
|
||||
}else{
|
||||
$stra .= ',`'.(string)$key.'`';
|
||||
$strb .= ','.(string)"'$val'";
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
$data['key'] = $stra;
|
||||
$data['val'] = $strb;
|
||||
return $data;
|
||||
}
|
||||
|
||||
//更新操作 格式( ['name'=>'王天佑',time=>'1234567890'] )
|
||||
public function update($data,$true=true){
|
||||
if(!is_array($data)){
|
||||
return false;
|
||||
}
|
||||
$data = $this->deal_update($data);
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$array = $this->do_sql();
|
||||
$make = isset($array['make'])?$array['make']:'';
|
||||
$sql = 'UPDATE '.$table.' SET '.$data.' '.$make;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_update($link,$sql);
|
||||
}
|
||||
//更新操作 sql操作
|
||||
public function query_update($link,$sql){
|
||||
$result = mysqli_query($link,$sql);
|
||||
$effet = mysqli_affected_rows($link);
|
||||
if($result && $effet>0){
|
||||
$res = $effet;
|
||||
//$this->close_db($link);
|
||||
return $res;
|
||||
}elseif(APP_DEBUG==1 && !$result){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//处理更新数据,组sql 格式['aaaa'=>'aaaa','bbbb'=>'bbbb']
|
||||
public function deal_update($data){
|
||||
$nums = 1;
|
||||
$counts = count($data);
|
||||
$str = '';
|
||||
foreach($data as $key=>$val){
|
||||
if($nums == $counts){
|
||||
$str .= $key.' = '.(string)"'$val'";
|
||||
}else{
|
||||
$str .= $key.' = '.(string)"'$val'".' , ';
|
||||
}
|
||||
$nums++;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//删除函操作 格式( ['name'=>'王天佑',time=>'1234567890'] )
|
||||
public function del($true=true){
|
||||
$data = $this->deal_del();
|
||||
$link = self::getInstance()->objdb;
|
||||
$table = $this->table_name;
|
||||
$sql = 'DELETE FROM '.$table.' '.$data;
|
||||
if($true == false){return $sql;}//输出sql
|
||||
return $this->query_del($link,$sql);
|
||||
}
|
||||
//删除函操作 sql操作
|
||||
public function query_del($link,$sql){
|
||||
$res = mysqli_query($link,$sql);
|
||||
$effet = mysqli_affected_rows($link);
|
||||
if($res){
|
||||
//$this->close_db($link);
|
||||
return $effet;
|
||||
}elseif(APP_DEBUG == 1 && !$res){
|
||||
exit("SQL:$sql <br />错误:" . $this->geterror());
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//处理删除函数
|
||||
public function deal_del(){
|
||||
$array = $this->options;
|
||||
if(empty($array)){
|
||||
return '';
|
||||
}
|
||||
$res = $this->deal_where($array);
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//原生sql操作
|
||||
public static function query($sql){
|
||||
$obj = self::getInstance();
|
||||
$link = $obj->objdb;
|
||||
$str_arr = explode(' ', $sql);
|
||||
$data = ['INSERT'=>'query_add','DELETE'=>'query_del','UPDATE'=>'query_update','SELECT'=>['count('=>'query_count','max('=>'query_max','min('=>'query_min','sum('=>'query_sum','avg('=>'query_avg']];
|
||||
$func_name = '';
|
||||
$a = strtoupper($str_arr[0]);
|
||||
$b = strtolower($str_arr[1]);
|
||||
foreach($data as $key=>$val){
|
||||
if($key == $a){
|
||||
if(is_string($val)){//属于增删改
|
||||
$func_name = $val;break;
|
||||
}else if(is_array($val)){//属于查
|
||||
foreach($val as $k=>$v){
|
||||
if(strpos($b,$k) === 0){
|
||||
$func_name = $v;break;
|
||||
}else{
|
||||
$func_name = 'query_select';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($func_name === ''){//sql不合法
|
||||
die("sql: ".'不合法');
|
||||
}else{
|
||||
return $obj->$func_name($link,$sql);
|
||||
}
|
||||
}
|
||||
|
||||
//数据库安装
|
||||
public static function establish($sql){
|
||||
$link = self::getInstance()->objdb;
|
||||
return mysqli_query($link,$sql);
|
||||
}
|
||||
|
||||
//关闭连接
|
||||
public function close_db($link){
|
||||
mysqli_close($link);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
define('DB_HOST','127.0.0.1');//数据库连接地址,默认:localhost或127.0.0.1
|
||||
define('DB_USER','tv');//数据库账号
|
||||
define('DB_PASSWD','aDtyFNpEYYXTHPn6');//数据库密码
|
||||
define('DB_NAME','tv');//数据库名称
|
||||
define('DB_PRE','eruyi_');//数据库前缀
|
||||
?>
|
||||
@@ -0,0 +1,516 @@
|
||||
<?php
|
||||
/*
|
||||
* File:Global.php
|
||||
* Author:易如意
|
||||
* QQ:51154393
|
||||
* Url:www.eruyi.cn
|
||||
*/
|
||||
header("content-type:text/html; charset=utf-8");
|
||||
require_once 'config.php'; //引入配置信息
|
||||
require_once 'db.class.php'; //引入数据库类
|
||||
require_once 'lang/lang_cp.php'; //引入日志配置
|
||||
|
||||
if (APP_DEBUG == 0) {
|
||||
error_reporting(0);
|
||||
} //关闭错误报告
|
||||
date_default_timezone_set(DEFAULT_TIMEZONE); //默认时区
|
||||
|
||||
if (defined('DB_PRE')) {
|
||||
$DP = DB_PRE;
|
||||
} else {
|
||||
$DP = '';
|
||||
}
|
||||
if (defined('DATA_PAGE_ENUMS')) {
|
||||
$ENUMS = DATA_PAGE_ENUMS;
|
||||
} else {
|
||||
$ENUMS = 10;
|
||||
}
|
||||
if (defined('USER_TOKEN_TIME')) {
|
||||
$UTT = time() - USER_TOKEN_TIME;
|
||||
} else {
|
||||
$UTT = time() - 1800;
|
||||
}
|
||||
|
||||
function out($code, $msg = null, $mi = null)
|
||||
{ //输出结果
|
||||
if ($msg && is_array($msg) && isset($msg['mi_state']) && isset($msg['mi_type'])) {
|
||||
$mi = $msg;
|
||||
$msg = null;
|
||||
}
|
||||
if (!$msg && !is_array($msg)) {
|
||||
require_once 'lang/lang_msg.php'; //返回数组
|
||||
$msg = $lang_msg[$code];
|
||||
}
|
||||
if (DEFAULT_RETURN_TYPE == 0) {
|
||||
if ($mi && is_array($mi) && isset($mi['mi_state']) && isset($mi['mi_type'])) {
|
||||
if ($mi['mi_state'] == 'y' && $mi['mi_type'] == 1) {
|
||||
if (is_array($msg)) {
|
||||
$msg = json_encode($msg);
|
||||
}
|
||||
$msg = mi_rc4($msg, $mi['mi_rc4_key']);
|
||||
} elseif ($mi['mi_state'] == 'y' && $mi['mi_type'] == 2) {
|
||||
if (is_array($msg)) {
|
||||
$msg = json_encode($msg);
|
||||
}
|
||||
$msg = RSA_SMI($msg, $app_res['mi_rsa_private_key']);
|
||||
}
|
||||
}
|
||||
$jdata = array('code' => $code, 'msg' => $msg, 'time' => time());
|
||||
$data = json_encode($jdata);
|
||||
} elseif (DEFAULT_RETURN_TYPE == 1) {
|
||||
require_once('class\Xml.php'); //引入类配置信息
|
||||
header("Content-type:text/xml"); //输出xml头信息
|
||||
$xml = new Array_to_Xml(); //实例化类
|
||||
if ($mi && is_array($mi) && isset($mi['mi_state']) && isset($mi['mi_type'])) {
|
||||
if ($mi['mi_state'] == 'y' && $mi['mi_type'] == 1) {
|
||||
if (is_array($msg)) {
|
||||
$msg = $xml->toXml($msg);
|
||||
}
|
||||
$msg = mi_rc4($msg, $mi['mi_rc4_key']);
|
||||
} elseif ($mi['mi_state'] == 'y' && $mi['mi_type'] == 2) {
|
||||
if (is_array($msg)) {
|
||||
$msg = $xml->toXml($msg);
|
||||
}
|
||||
$msg = RSA_SMI($msg, $app_res['mi_rsa_private_key']);
|
||||
}
|
||||
}
|
||||
$res = array('code' => $code, 'msg' => $msg, 'time' => time());
|
||||
$data = $xml->toXml($res); //转为数组
|
||||
}
|
||||
// Encrypted($_SERVER['HTTP_HOST'], json_encode($obj, JSON_UNESCAPED_SLASHES)
|
||||
echo $data;
|
||||
exit;
|
||||
}
|
||||
|
||||
function encryptionout($code, $msg = null, $mi = null)
|
||||
{ //输出结果
|
||||
if ($msg && is_array($msg) && isset($msg['mi_state']) && isset($msg['mi_type'])) {
|
||||
$mi = $msg;
|
||||
$msg = null;
|
||||
}
|
||||
if (!$msg && !is_array($msg)) {
|
||||
require_once 'lang/lang_msg.php'; //返回数组
|
||||
$msg = $lang_msg[$code];
|
||||
}
|
||||
|
||||
$jdata = array('code' => $code, 'msg' => $msg, 'time' => time());
|
||||
$data = json_encode($jdata);
|
||||
|
||||
echo Encrypted($_SERVER['HTTP_HOST'], $data);
|
||||
exit;
|
||||
}
|
||||
|
||||
function timeRange($dayName = '', $date = FALSE)
|
||||
{
|
||||
$startFix = ' 00:00:00';
|
||||
$endFix = ' 23:59:59';
|
||||
$day = date('Y-m-d');
|
||||
|
||||
//当天 昨天 最近三天 最近七天 本月 上月
|
||||
//if($dayName)
|
||||
|
||||
$data['t_a'] = $day . $startFix; //今天开始
|
||||
$data['t_b'] = $day . $endFix; //今天结束
|
||||
|
||||
$data['zt_a'] = date('Y-m-d', strtotime('-1 day')) . $startFix; //昨天开始
|
||||
$data['zt_b'] = date('Y-m-d', strtotime('-1 day')) . $endFix; //昨天结束
|
||||
|
||||
$data['t3_a'] = date('Y-m-d', strtotime('-3 day')) . $startFix; //最近三天开始
|
||||
$data['t3_b'] = date('Y-m-d H:i:s'); //最近三天结束
|
||||
|
||||
$data['t7_a'] = date('Y-m-d', strtotime('-7 day')) . $startFix; //最近三天开始
|
||||
$data['t7_b'] = date('Y-m-d H:i:s'); //最近三天结束
|
||||
|
||||
$data['yue_a'] = date('Y-m-01', strtotime(date("Y-m-d"))) . $startFix; //本月开始
|
||||
$data['yue_b'] = date('Y-m-d', strtotime($data['yue_a'] . ' +1 month -1 day')) . $endFix; //本月结束
|
||||
|
||||
$data['syue_a'] = date('Y-m-01', strtotime('-1 month')) . $startFix; //上月开始
|
||||
$data['syue_b'] = date('Y-m-t', strtotime('-1 month')) . $endFix; //上月结束
|
||||
|
||||
if ($date == true) {
|
||||
return $dayName ? $data[$dayName] : $data;
|
||||
} else {
|
||||
return $dayName ? strtotime($data[$dayName]) : $data;
|
||||
}
|
||||
}
|
||||
|
||||
function pagination($count, $perlogs, $page, $url)
|
||||
{
|
||||
$pnums = @ceil($count / $perlogs);
|
||||
$re = '';
|
||||
$urlHome = preg_replace("|[\?&/][^\./\?&=]*page[=/\-]|", "", $url);
|
||||
for ($i = $page - 2; $i <= $page + 2 && $i <= $pnums; $i++) {
|
||||
if ($i > 0) {
|
||||
if ($i == $page) {
|
||||
$re .= "<li class=\"page-item active\"><a class=\"page-link\">$i</a></li>";
|
||||
//$re ."<li class=\"page-item active\"><a class=\"page-link\" >$i</a></li>";
|
||||
//$re .= "<li><span>$i</span></li>";
|
||||
} elseif ($i == 1) {
|
||||
|
||||
$re .= "<li class=\"page-item\"><a class=\"page-link\" href=\"$urlHome\">$i</a></li>";
|
||||
} else {
|
||||
$re .= "<li class=\"page-item\"><a class=\"page-link\" href=\"$url$i\">$i</a></li>";
|
||||
//$re .= "<li><a href=\"$url$i\">$i</a></li>";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($page > 0)
|
||||
if ($pnums > $page) { //前进
|
||||
$go = $page + 1;
|
||||
} else {
|
||||
$go = $page;
|
||||
}
|
||||
if ($page > 1) {
|
||||
$after = $page - 1;
|
||||
} else {
|
||||
$after = $page;
|
||||
}
|
||||
|
||||
$re = "<li class=\"page-item\"> <a class=\"page-link\" href=\"$url$after\" aria-label=\"Previous\"> <span aria-hidden=\"true\">«</span> <span class=\"sr-only\">Previous</span> </a> </li>$re";
|
||||
$re .= "<li class=\"page-item\"><a class=\"page-link\" href=\"$url$go\" aria-label=\"Next\"><span aria-hidden=\"true\">»</span><span class=\"sr-only\">Next</span></a></li>";
|
||||
if ($pnums <= 1)
|
||||
$re = '';
|
||||
return "<ul class=\"pagination justify-content-end\">" . $re . "</ul>";
|
||||
}
|
||||
|
||||
function getIp()
|
||||
{
|
||||
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
|
||||
if (!ip2long($ip)) {
|
||||
$ip = '';
|
||||
}
|
||||
return $ip;
|
||||
}
|
||||
|
||||
function getcode($length)
|
||||
{ //取随机字符
|
||||
$str = null;
|
||||
// $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
$strPol = "0123456789";
|
||||
$max = strlen($strPol) - 1;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$str .= $strPol[rand(0, $max)];
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function json($code, $msg)
|
||||
{ //json输出
|
||||
$udata = array('code' => $code, 'msg' => $msg);
|
||||
$jdata = json_encode($udata);
|
||||
echo $jdata;
|
||||
exit;
|
||||
}
|
||||
|
||||
function send_mail($to, $name, $subject = '', $body = '', $attachment = null, $config = '')
|
||||
{ //发送邮件
|
||||
$config = is_array($config) ? $config : array();
|
||||
require_once 'class/email/phpmailer.class.php';
|
||||
$mail = new PHPMailer(); //PHPMailer对象
|
||||
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
|
||||
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||
//$mail->IsHTML(true);
|
||||
$mail->SMTPDebug = 0; // 关闭SMTP调试功能 1 = errors and messages2 = messages only
|
||||
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||
if ($config['smtp_port'] == 465)
|
||||
$mail->SMTPSecure = 'ssl'; // 使用安全协议
|
||||
$mail->Host = $config['smtp_host']; // SMTP 服务器
|
||||
$mail->Port = $config['smtp_port']; // SMTP服务器的端口号
|
||||
$mail->Username = $config['smtp_user']; // SMTP服务器用户名
|
||||
$mail->Password = $config['smtp_pass']; // SMTP服务器密码
|
||||
$mail->SetFrom($config['from_email'], $config['from_name']);
|
||||
$replyEmail = $config['reply_email'] ? $config['reply_email'] : $config['reply_email'];
|
||||
$replyName = $config['reply_name'] ? $config['reply_name'] : $config['reply_name'];
|
||||
$mail->AddReplyTo($replyEmail, $replyName);
|
||||
$mail->Subject = $subject;
|
||||
$mail->MsgHTML($body);
|
||||
$mail->AddAddress($to, $name);
|
||||
/*if (is_array($attachment)) { // 添加附件
|
||||
foreach ($attachment as $file) {
|
||||
if (is_array($file)) {
|
||||
is_file($file['path']) && $mail->AddAttachment($file['path'], $file['name']);
|
||||
} else {
|
||||
is_file($file) && $mail->AddAttachment($file);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
is_file($attachment) && $mail->AddAttachment($attachment);
|
||||
}*/
|
||||
return $mail->Send() ? true : $mail->ErrorInfo;
|
||||
}
|
||||
|
||||
function http_post($url, $data = null, $ua = '')
|
||||
{ //发送httppost请求
|
||||
require_once 'class/HttpCurl.php';
|
||||
$http = new HttpCurl();
|
||||
if (!empty($ua)) {
|
||||
$result = $http->userAgent($ua)->post($url, $data);
|
||||
} else {
|
||||
$result = $http->post($url, $data);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function http_gets($url, $data = null)
|
||||
{ //发送httpget请求
|
||||
require_once 'class/HttpCurl.php';
|
||||
$http = new HttpCurl();
|
||||
$result = $http->get($url, $data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function get_pic($pic_url, $dirname = FALSE)
|
||||
{ //取头像链接
|
||||
if (substr($pic_url, 0, 4) == 'http') {
|
||||
return $pic_url;
|
||||
} else {
|
||||
if (substr($pic_url, 0, 5) == '/pic/') {
|
||||
$pic_url = str_replace(substr($pic_url, 0, 5), '', $pic_url);
|
||||
}
|
||||
if ($dirname) {
|
||||
return dirname(WEB_URL) . '/' . USER_PIC_MULU . $pic_url;
|
||||
} else {
|
||||
return WEB_URL . '/' . USER_PIC_MULU . $pic_url;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function purge($string, $trim = true, $filter = true, $force = 0, $strip = FALSE)
|
||||
{ //递归addslashes 对参数进行净化
|
||||
$encode = mb_detect_encoding($string, array("ASCII", "UTF-8", "GB2312", "GBK", "BIG5"));
|
||||
if ($encode != 'UTF-8') {
|
||||
$string = iconv($encode, 'UTF-8', $string);
|
||||
}
|
||||
if ($trim) {
|
||||
$string = preg_replace('/\s+/', '', $string);
|
||||
}
|
||||
if ($filter) {
|
||||
$farr = array(
|
||||
"/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
|
||||
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
|
||||
"/select |insert |and |or |create |update |delete |alter |count |\'|\/\*|\*|\.\.\/|\.\/|\^|union |into |load_file|outfile |dump/is"
|
||||
);
|
||||
$string = preg_replace($farr, '', $string);
|
||||
}
|
||||
!defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
|
||||
if (!MAGIC_QUOTES_GPC || $force) {
|
||||
if (is_array($string)) {
|
||||
foreach ($string as $key => $val) {
|
||||
$string[$key] = purge($val, $force, $strip);
|
||||
}
|
||||
} else {
|
||||
$string = addslashes($strip ? stripslashes($string) : $string);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
function check_phone($phone)
|
||||
{ //匹配手机号
|
||||
return preg_match('#^13[\d]{9}$|^14[5,6,7,8,9]{1}\d{8}$|^15[^4]{1}\d{8}$|^16[6]{1}\d{8}$|^17[0,1,2,3,4,5,6,7,8]{1}\d{8}$|^18[\d]{9}$|^19[8,9]{1}\d{8}$#', $phone) ? true : false;
|
||||
}
|
||||
|
||||
function check_email($email)
|
||||
{ //匹配邮箱
|
||||
return preg_match('/^[a-z0-9]+([._-][a-z0-9]+)*@([0-9a-z]+\.[a-z]{2,14}(\.[a-z]{2})?)$/i', $email) ? true : false;
|
||||
}
|
||||
|
||||
function foreachArray($array = [], $count = 0)
|
||||
{ //数组维度判断
|
||||
if (!is_array($array)) {
|
||||
return $count;
|
||||
}
|
||||
foreach ($array as $value) {
|
||||
$count++;
|
||||
if (!is_array($value)) {
|
||||
return $count;
|
||||
}
|
||||
return foreachArray($value, $count);
|
||||
}
|
||||
}
|
||||
|
||||
function Arr_sign($arr, $key, $md5 = true)
|
||||
{ //数组签名
|
||||
unset($arr['sign']);
|
||||
unset($arr['app']);
|
||||
unset($arr['act']);
|
||||
$sign = '';
|
||||
foreach ($arr as $k => $v) {
|
||||
$sign = $sign . $k . '=' . $v . '&';
|
||||
}
|
||||
$sign = $sign . $key;
|
||||
if ($md5) {
|
||||
return md5($sign);
|
||||
} else {
|
||||
return $sign;
|
||||
}
|
||||
}
|
||||
|
||||
function txt_Arr($txt)
|
||||
{ //文本转数组
|
||||
$arr = explode('&', $txt);
|
||||
$array = [];
|
||||
foreach ($arr as $value) {
|
||||
$tmp_arr = explode('=', $value);
|
||||
if (is_array($tmp_arr) && count($tmp_arr) == 2) {
|
||||
$array = array_merge($array, [$tmp_arr[0] => $tmp_arr[1]]);
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
function txt_zhong($str, $leftStr, $rightStr)
|
||||
{ //取文本中间
|
||||
$left = strpos($str, $leftStr);
|
||||
//echo '左边:'.$left;
|
||||
$right = strpos($str, $rightStr, $left);
|
||||
//echo '<br>右边:'.$right;
|
||||
if ($left < 0 or $right < $left) return '';
|
||||
return substr($str, $left + strlen($leftStr), $right - $left - strlen($leftStr));
|
||||
}
|
||||
|
||||
function txt_you($str, $leftStr)
|
||||
{ //取文本右边
|
||||
$left = strpos($str, $leftStr);
|
||||
return substr($str, $left + strlen($leftStr));
|
||||
}
|
||||
|
||||
function txt_zuo($str, $rightStr)
|
||||
{ //取文本左边
|
||||
$right = strpos($str, $rightStr);
|
||||
return substr($str, 0, $right);
|
||||
}
|
||||
|
||||
function mi_rc4($data, $pwd, $t = 0)
|
||||
{ //t=0加密,1=解密
|
||||
$cipher = '';
|
||||
$key[] = "";
|
||||
$box[] = "";
|
||||
$pwd = mi_rc4_encode($pwd);
|
||||
$data = mi_rc4_encode($data);
|
||||
$pwd_length = strlen($pwd);
|
||||
if ($t == 1) {
|
||||
$data = hex2bin($data);
|
||||
}
|
||||
$data_length = strlen($data);
|
||||
for ($i = 0; $i < 256; $i++) {
|
||||
$key[$i] = ord($pwd[$i % $pwd_length]);
|
||||
$box[$i] = $i;
|
||||
}
|
||||
for ($j = $i = 0; $i < 256; $i++) {
|
||||
$j = ($j + $box[$i] + $key[$i]) % 256;
|
||||
$tmp = $box[$i];
|
||||
$box[$i] = $box[$j];
|
||||
$box[$j] = $tmp;
|
||||
}
|
||||
for ($a = $j = $i = 0; $i < $data_length; $i++) {
|
||||
$a = ($a + 1) % 256;
|
||||
$j = ($j + $box[$a]) % 256;
|
||||
$tmp = $box[$a];
|
||||
$box[$a] = $box[$j];
|
||||
$box[$j] = $tmp;
|
||||
$k = $box[(($box[$a] + $box[$j]) % 256)];
|
||||
$cipher .= chr(ord($data[$i]) ^ $k);
|
||||
}
|
||||
if ($t == 1) {
|
||||
return $cipher;
|
||||
} else {
|
||||
return bin2hex($cipher);
|
||||
}
|
||||
}
|
||||
|
||||
function swap(&$var_0, &$var_1)
|
||||
{
|
||||
$var_2 = $var_0;
|
||||
$var_0 = $var_1;
|
||||
$var_1 = $var_2;
|
||||
}
|
||||
|
||||
function Encrypted($var_3, $var_4, $var_5 = false)
|
||||
{
|
||||
$var_6 = strlen($var_3);
|
||||
$var_7 = array();
|
||||
$var_8 = 0;
|
||||
while ($var_8 < 256) {
|
||||
$var_7[$var_8] = $var_8;
|
||||
$var_8++;
|
||||
}
|
||||
$var_9 = 0;
|
||||
$var_8 = 0;
|
||||
while ($var_8 < 256) {
|
||||
$var_9 = ($var_9 + $var_7[$var_8] + ord($var_3[$var_8 % $var_6])) % 256;
|
||||
swap($var_7[$var_8], $var_7[$var_9]);
|
||||
$var_8++;
|
||||
}
|
||||
|
||||
$var_10 = strlen($var_4);
|
||||
$var_11 = base64_decode('');
|
||||
$var_0 = $var_9 = $var_8 = 0;
|
||||
while ($var_8 < $var_10) {
|
||||
$var_0 = ($var_0 + 1) % 256;
|
||||
$var_9 = ($var_9 + $var_7[$var_0]) % 256;
|
||||
swap($var_7[$var_0], $var_7[$var_9]);
|
||||
$var_12 = $var_7[($var_7[$var_0] + $var_7[$var_9]) % 256];
|
||||
$var_11 .= chr(ord($var_4[$var_8]) ^ $var_12);
|
||||
$var_8++;
|
||||
}
|
||||
return $var_5 ? $var_11 : bin2hex($var_11);
|
||||
}
|
||||
|
||||
function mi_rc4_encode($str, $turn = 0)
|
||||
{ //turn=0,utf8转gbk,1=gbk转utf8
|
||||
if (is_array($str)) {
|
||||
foreach ($str as $k => $v) {
|
||||
$str[$k] = array_iconv($v);
|
||||
}
|
||||
return $str;
|
||||
} else {
|
||||
if (is_string($str) && $turn == 0) {
|
||||
return mb_convert_encoding($str, 'GBK', 'UTF-8');
|
||||
} elseif (is_string($str) && $turn == 1) {
|
||||
return mb_convert_encoding($str, 'UTF-8', 'GBK');
|
||||
} else {
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function RSA_GMI($data, $key, $t = 0)
|
||||
{ //RSA公钥加解密
|
||||
require_once 'class/Rsa.php'; //引入RSA加解密类
|
||||
if ($t == 0) {
|
||||
$mi_data = Rsa::publicEncrypt($data, $key); //使用公钥将数据加密
|
||||
} else {
|
||||
$mi_data = Rsa::publicDecrypt($data, $key); //使用公钥将数据解密
|
||||
}
|
||||
return $mi_data;
|
||||
}
|
||||
|
||||
function RSA_SMI($data, $key, $t = 0)
|
||||
{ //RSA私钥加解密
|
||||
require_once 'class/Rsa.php'; //引入RSA加解密类
|
||||
if ($t == 0) {
|
||||
$mi_data = Rsa::privateEncrypt($data, $key); //使用私钥将数据加密
|
||||
} else {
|
||||
$mi_data = Rsa::privateDecrypt($data, $key); //使用私钥将数据解密
|
||||
}
|
||||
return $mi_data;
|
||||
}
|
||||
|
||||
function myScanDir($dir, $type = 0)
|
||||
{ //PHP 实现遍历出目录及其子文件
|
||||
$file_arr = scandir($dir);
|
||||
$new_arr = [];
|
||||
foreach ($file_arr as $item) {
|
||||
//echo $item.'<br>';
|
||||
if ($type == 0 && $item != ".." && $item != ".") { //目录和文件
|
||||
$new_arr[] = $item;
|
||||
} elseif ($type == 1 && is_dir($dir . '/' . $item) && $item != ".." && $item != ".") { //只要目录
|
||||
$new_arr[] = $item;
|
||||
} elseif ($type == 2 && is_file($dir . '/' . $item) && $item != ".." && $item != ".") { //只要文件
|
||||
$new_arr[] = $item;
|
||||
}
|
||||
}
|
||||
return $new_arr;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
$lang_adm = [//管理日志
|
||||
'logon' => '后台登录',
|
||||
'app_add' => '添加应用',
|
||||
'app_edit' => '编辑应用',
|
||||
'app_del' => '删除应用',
|
||||
'exten_add'=>'添加扩展配置',
|
||||
'exten_edit'=>'编辑扩展配置',
|
||||
'exten_del'=>'删除扩展配置',
|
||||
'notice_add'=>'发布通知',
|
||||
'notice_del'=>'删除通知',
|
||||
'user_add'=>'添加用户',
|
||||
'user_edit'=>'编辑用户',
|
||||
'user_del'=>'删除用户',
|
||||
'fen_add'=>'添加积分事件',
|
||||
'fen_edit'=>'编辑积分事件',
|
||||
'fen_del'=>'删除积分事件',
|
||||
'fen_o_del'=>'删除积分订单',
|
||||
'goods_add'=>'添加商品',
|
||||
'goods_edit'=>'编辑商品',
|
||||
'goods_del'=>'删除商品',
|
||||
'goods_o_del'=>'删除商品订单',
|
||||
'kami_add'=>'添加卡密',
|
||||
'kami_note'=>'备注卡密',
|
||||
'kami_state'=>'禁用卡密',
|
||||
'kami_del'=>'删除卡密',
|
||||
'web_set'=>'更改系统配置',
|
||||
'web_pswd'=>'修改管理员账号密码',
|
||||
];
|
||||
|
||||
$lang_user = [//用户操作日志
|
||||
'user_logon' => '登录',
|
||||
'inv' => '邀请注册',
|
||||
'upic' => '上传头像',
|
||||
'set_up' => '设置账号密码',
|
||||
'alter_name' => '修改名称',
|
||||
'afcrc' => '获取验证码',
|
||||
'alter_pass' => '修改密码',
|
||||
'pay' => '请求支付',
|
||||
'get_fen' => '积分验证',
|
||||
'clock' => '打卡签到',
|
||||
'card' => '卡密充值',
|
||||
'wx_login' => '微信登录',
|
||||
'wx_bind' => '绑定微信',
|
||||
'qq_login' => 'QQ登录',
|
||||
'qq_bind' => '绑定QQ',
|
||||
'seek_pass'=>'找回密码',
|
||||
'email_bind' => '绑定邮箱',
|
||||
'email_untie' => '解绑邮箱',
|
||||
'pay_success' => '在线充值',
|
||||
];
|
||||
|
||||
$time_type = [//用户会员变化类型
|
||||
'inv' => '小时',
|
||||
'clock' => '分钟',
|
||||
'card' => '天',
|
||||
'pay_success' => '天',
|
||||
];
|
||||
?>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
$lang_msg = array(
|
||||
200 => '成功',
|
||||
201 => '失败',
|
||||
100 => '请绑定应用ID',
|
||||
101 => '应用不存在',
|
||||
102 => '应用已关闭',
|
||||
103 => '已关闭登录',
|
||||
104 => '签名为空',
|
||||
105 => '数据过期',
|
||||
106 => '签名有误',
|
||||
107 => '数据为空',
|
||||
108 => '未发现时间变量',
|
||||
110 => '请填写账号',
|
||||
111 => '请填写密码',
|
||||
112 => '请填写机器码',
|
||||
113 => '账号密码不正确',
|
||||
114 => '账号已被禁用',
|
||||
115 => '账号已存在',
|
||||
116 => '账号不合法',
|
||||
117 => '账号注册频率过快',
|
||||
118 => '邀请人不存在',
|
||||
119 => '密码不合法',
|
||||
120 => '验证码为空',
|
||||
121 => '管理员未启动邮箱验证码功能',
|
||||
122 => '账号不存在',
|
||||
123 => '验证码发送频率过快',
|
||||
124 => '验证码不正确',
|
||||
125 => 'TOKEN为空',
|
||||
126 => 'TOKEN不合法',
|
||||
127 => 'TOKEN不存在',
|
||||
128 => '已设置账号不可更改',
|
||||
129 => '名称为空',
|
||||
130 => '订单号为空',
|
||||
131 => '请选择支付方式',
|
||||
132 => '请选择商品',
|
||||
133 => '该应用未开启支付功能',
|
||||
134 => '请先设置异步通知地址',
|
||||
135 => '不支持该支付方式',
|
||||
136 => '商品不存在',
|
||||
137 => '订单入库失败',
|
||||
138 => '支付错误信息',
|
||||
139 => '支付未知错误',
|
||||
140 => '请填写订单信息',
|
||||
141 => '提交方式有误',
|
||||
142 => '上传类型不支持',
|
||||
143 => '积分ID为空',
|
||||
144 => '积分事件不存在',
|
||||
145 => '积分事件已关闭',
|
||||
146 => '签到功能未启用',
|
||||
147 => '今天已经签到过了',
|
||||
148 => '卡密为空',
|
||||
149 => '卡密不存在',
|
||||
150 => '卡密已使用',
|
||||
151 => '卡密已被禁用',
|
||||
152 => '卡密类型不一致',
|
||||
153 => '订单不存在',
|
||||
154 => '等待支付',
|
||||
155 => '未知订单状态',
|
||||
156 => '请输入openid',
|
||||
157 => '请输入access_token',
|
||||
158 => '身份信息错误',
|
||||
159 => '微信openid有误',
|
||||
160 => '该微信已绑定其他账号',
|
||||
161 => '请输入QQ互联ID',
|
||||
162 => '未知登录错误',
|
||||
163 => '该应用不允许使用此种登录方式',
|
||||
164 => '该应用不允许使用当前操作',
|
||||
165 => '当前账号未绑定邮箱',
|
||||
166 => '一张被充值的卡密只能充值给一个账号或者一张主卡密',
|
||||
167 => '不支持积分卡登录',
|
||||
168 => '订单已存在',
|
||||
199 => '您已经是永久会员了',
|
||||
400 => '没有相关操作',
|
||||
401 => '错误的数据',
|
||||
|
||||
);
|
||||
?>
|
||||
Reference in New Issue
Block a user