81 changed files with 35531 additions and 0 deletions
@ -0,0 +1,225 @@ |
|||
<?php |
|||
if (!defined('IN_IA')) { |
|||
exit('Access Denied'); |
|||
} |
|||
class Smsnum { |
|||
/** |
|||
* 公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用 |
|||
**/ |
|||
private $extend; |
|||
|
|||
/** |
|||
* 短信接收号码。支持单个或多个手机号码,传入号码为11位手机号码,不能加0或+86。群发短信需传入多个号码,以英文逗号分隔,一次调用最多传入200个号码。示例:18600000000,13911111111,13322222222 |
|||
**/ |
|||
private $recNum; |
|||
|
|||
/** |
|||
* 短信签名,传入的短信签名必须是在阿里大鱼“管理中心-短信签名管理”中的可用签名。如“阿里大鱼”已在短信签名管理中通过审核,则可传入”阿里大鱼“(传参时去掉引号)作为短信签名。短信效果示例:【阿里大鱼】欢迎使用阿里大鱼服务。 |
|||
**/ |
|||
private $smsFreeSignName; |
|||
|
|||
/** |
|||
* 短信模板变量,传参规则{"key":"value"},key的名字须和申请模板中的变量名一致,多个变量之间以逗号隔开。示例:针对模板“验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!”,传参时需传入{"code":"1234","product":"alidayu"} |
|||
**/ |
|||
private $smsParam; |
|||
|
|||
/** |
|||
* 短信模板ID,传入的模板必须是在阿里大鱼“管理中心-短信模板管理”中的可用模板。示例:SMS_585014 |
|||
**/ |
|||
private $smsTemplateCode; |
|||
|
|||
/** |
|||
* 短信类型,传入值请填写normal |
|||
**/ |
|||
private $smsType; |
|||
|
|||
private $apiParas = array(); |
|||
|
|||
public function setExtend($extend) |
|||
{ |
|||
$this->extend = $extend; |
|||
$this->apiParas["extend"] = $extend; |
|||
} |
|||
|
|||
public function getExtend() |
|||
{ |
|||
return $this->extend; |
|||
} |
|||
|
|||
public function setRecNum($recNum) |
|||
{ |
|||
$this->recNum = $recNum; |
|||
$this->apiParas["rec_num"] = $recNum; |
|||
} |
|||
|
|||
public function getRecNum() |
|||
{ |
|||
return $this->recNum; |
|||
} |
|||
|
|||
public function setSmsFreeSignName($smsFreeSignName) |
|||
{ |
|||
$this->smsFreeSignName = $smsFreeSignName; |
|||
$this->apiParas["sms_free_sign_name"] = $smsFreeSignName; |
|||
} |
|||
|
|||
public function getSmsFreeSignName() |
|||
{ |
|||
return $this->smsFreeSignName; |
|||
} |
|||
|
|||
public function setSmsParam($smsParam) |
|||
{ |
|||
$this->smsParam = $smsParam; |
|||
$this->apiParas["sms_param"] = $smsParam; |
|||
} |
|||
|
|||
public function getSmsParam() |
|||
{ |
|||
return $this->smsParam; |
|||
} |
|||
|
|||
public function setSmsTemplateCode($smsTemplateCode) |
|||
{ |
|||
$this->smsTemplateCode = $smsTemplateCode; |
|||
$this->apiParas["sms_template_code"] = $smsTemplateCode; |
|||
} |
|||
|
|||
public function getSmsTemplateCode() |
|||
{ |
|||
return $this->smsTemplateCode; |
|||
} |
|||
|
|||
public function setSmsType($smsType) |
|||
{ |
|||
$this->smsType = $smsType; |
|||
$this->apiParas["sms_type"] = $smsType; |
|||
} |
|||
|
|||
public function getSmsType() |
|||
{ |
|||
return $this->smsType; |
|||
} |
|||
|
|||
public function getApiMethodName() |
|||
{ |
|||
return "alibaba.aliqin.fc.sms.num.send"; |
|||
} |
|||
|
|||
public function getApiParas() |
|||
{ |
|||
return $this->apiParas; |
|||
} |
|||
|
|||
public function check() |
|||
{ |
|||
|
|||
RequestCheckUtil::checkNotNull($this->recNum,"recNum"); |
|||
RequestCheckUtil::checkNotNull($this->smsFreeSignName,"smsFreeSignName"); |
|||
RequestCheckUtil::checkNotNull($this->smsTemplateCode,"smsTemplateCode"); |
|||
RequestCheckUtil::checkNotNull($this->smsType,"smsType"); |
|||
} |
|||
|
|||
public function putOtherTextParam($key, $value) { |
|||
$this->apiParas[$key] = $value; |
|||
$this->$key = $value; |
|||
} |
|||
} |
|||
class RequestCheckUtil |
|||
{ |
|||
/** |
|||
* 校验字段 fieldName 的值$value非空 |
|||
* |
|||
**/ |
|||
public static function checkNotNull($value,$fieldName) { |
|||
|
|||
if(self::checkEmpty($value)){ |
|||
throw new Exception("client-check-error:Missing Required Arguments: " .$fieldName , 40); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检验字段fieldName的值value 的长度 |
|||
* |
|||
**/ |
|||
public static function checkMaxLength($value,$maxLength,$fieldName){ |
|||
if(!self::checkEmpty($value) && mb_strlen($value , "UTF-8") > $maxLength){ |
|||
throw new Exception("client-check-error:Invalid Arguments:the length of " .$fieldName . " can not be larger than " . $maxLength . "." , 41); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检验字段fieldName的值value的最大列表长度 |
|||
* |
|||
**/ |
|||
public static function checkMaxListSize($value,$maxSize,$fieldName) { |
|||
|
|||
if(self::checkEmpty($value)) |
|||
return ; |
|||
|
|||
$list=preg_split("/,/",$value); |
|||
if(count($list) > $maxSize){ |
|||
throw new Exception("client-check-error:Invalid Arguments:the listsize(the string split by \",\") of ". $fieldName . " must be less than " . $maxSize . " ." , 41); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检验字段fieldName的值value 的最大值 |
|||
* |
|||
**/ |
|||
public static function checkMaxValue($value,$maxValue,$fieldName){ |
|||
|
|||
if(self::checkEmpty($value)) |
|||
return ; |
|||
|
|||
self::checkNumeric($value,$fieldName); |
|||
|
|||
if($value > $maxValue){ |
|||
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be larger than " . $maxValue ." ." , 41); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检验字段fieldName的值value 的最小值 |
|||
* |
|||
**/ |
|||
public static function checkMinValue($value,$minValue,$fieldName) { |
|||
|
|||
if(self::checkEmpty($value)) |
|||
return ; |
|||
|
|||
self::checkNumeric($value,$fieldName); |
|||
|
|||
if($value < $minValue){ |
|||
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " can not be less than " . $minValue . " ." , 41); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 检验字段fieldName的值value是否是number |
|||
* |
|||
**/ |
|||
protected static function checkNumeric($value,$fieldName) { |
|||
if(!is_numeric($value)) |
|||
throw new Exception("client-check-error:Invalid Arguments:the value of " . $fieldName . " is not number : " . $value . " ." , 41); |
|||
} |
|||
|
|||
/** |
|||
* 校验$value是否非空 |
|||
* if not set ,return true; |
|||
* if is null , return true; |
|||
* |
|||
* |
|||
**/ |
|||
public static function checkEmpty($value) { |
|||
if(!isset($value)) |
|||
return true ; |
|||
if($value === null ) |
|||
return true; |
|||
if(trim($value) === "") |
|||
return true; |
|||
|
|||
return false; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,342 @@ |
|||
<?php |
|||
if (!defined('IN_IA')) { |
|||
exit('Access Denied'); |
|||
} |
|||
class Topclient { |
|||
|
|||
public $appkey; |
|||
|
|||
public $secretKey; |
|||
|
|||
public $gatewayUrl = "http://gw.api.taobao.com/router/rest"; |
|||
|
|||
public $format = "json"; |
|||
|
|||
public $connectTimeout; |
|||
|
|||
public $readTimeout; |
|||
|
|||
/** 是否打开入参check**/ |
|||
public $checkRequest = true; |
|||
|
|||
protected $signMethod = "md5"; |
|||
|
|||
protected $apiVersion = "2.0"; |
|||
|
|||
protected $sdkVersion = "top-sdk-php-20151012"; |
|||
|
|||
public function __construct($appkey = "",$secretKey = ""){ |
|||
$this->appkey = $appkey; |
|||
$this->secretKey = $secretKey ; |
|||
} |
|||
|
|||
protected function generateSign($params) |
|||
{ |
|||
ksort($params); |
|||
|
|||
$stringToBeSigned = $this->secretKey; |
|||
foreach ($params as $k => $v) |
|||
{ |
|||
if("@" != substr($v, 0, 1)) |
|||
{ |
|||
$stringToBeSigned .= "$k$v"; |
|||
} |
|||
} |
|||
unset($k, $v); |
|||
$stringToBeSigned .= $this->secretKey; |
|||
|
|||
return strtoupper(md5($stringToBeSigned)); |
|||
} |
|||
|
|||
public function curl($url, $postFields = null) |
|||
{ |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_URL, $url); |
|||
curl_setopt($ch, CURLOPT_FAILONERROR, false); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
if ($this->readTimeout) { |
|||
curl_setopt($ch, CURLOPT_TIMEOUT, $this->readTimeout); |
|||
} |
|||
if ($this->connectTimeout) { |
|||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout); |
|||
} |
|||
curl_setopt ( $ch, CURLOPT_USERAGENT, "top-sdk-php" ); |
|||
//https 请求 |
|||
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) { |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|||
} |
|||
|
|||
if (is_array($postFields) && 0 < count($postFields)) |
|||
{ |
|||
$postBodyString = ""; |
|||
$postMultipart = false; |
|||
foreach ($postFields as $k => $v) |
|||
{ |
|||
if("@" != substr($v, 0, 1))//判断是不是文件上传 |
|||
{ |
|||
$postBodyString .= "$k=" . urlencode($v) . "&"; |
|||
} |
|||
else//文件上传用multipart/form-data,否则用www-form-urlencoded |
|||
{ |
|||
$postMultipart = true; |
|||
if(class_exists('\CURLFile')){ |
|||
$postFields[$k] = new \CURLFile(substr($v, 1)); |
|||
} |
|||
} |
|||
} |
|||
unset($k, $v); |
|||
curl_setopt($ch, CURLOPT_POST, true); |
|||
if ($postMultipart) |
|||
{ |
|||
if (class_exists('\CURLFile')) { |
|||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); |
|||
} else { |
|||
if (defined('CURLOPT_SAFE_UPLOAD')) { |
|||
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); |
|||
} |
|||
} |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); |
|||
} |
|||
else |
|||
{ |
|||
$header = array("content-type: application/x-www-form-urlencoded; charset=UTF-8"); |
|||
curl_setopt($ch,CURLOPT_HTTPHEADER,$header); |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1)); |
|||
} |
|||
} |
|||
$reponse = curl_exec($ch); |
|||
|
|||
if (curl_errno($ch)) |
|||
{ |
|||
throw new Exception(curl_error($ch),0); |
|||
} |
|||
else |
|||
{ |
|||
$httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|||
if (200 !== $httpStatusCode) |
|||
{ |
|||
throw new Exception($reponse,$httpStatusCode); |
|||
} |
|||
} |
|||
curl_close($ch); |
|||
return $reponse; |
|||
} |
|||
|
|||
protected function logCommunicationError($apiName, $requestUrl, $errorCode, $responseTxt) |
|||
{ |
|||
$localIp = isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : "CLI"; |
|||
$logger = new TopLogger; |
|||
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_comm_err_" . $this->appkey . "_" . date("Y-m-d") . ".log"; |
|||
$logger->conf["separator"] = "^_^"; |
|||
$logData = array( |
|||
date("Y-m-d H:i:s"), |
|||
$apiName, |
|||
$this->appkey, |
|||
$localIp, |
|||
PHP_OS, |
|||
$this->sdkVersion, |
|||
$requestUrl, |
|||
$errorCode, |
|||
str_replace("\n","",$responseTxt) |
|||
); |
|||
$logger->log($logData); |
|||
} |
|||
|
|||
public function execute($request, $session = null,$bestUrl = null) |
|||
{ |
|||
$result = new ResultSet(); |
|||
if($this->checkRequest) { |
|||
try { |
|||
$request->check(); |
|||
} catch (Exception $e) { |
|||
|
|||
$result->code = $e->getCode(); |
|||
$result->msg = $e->getMessage(); |
|||
return $result; |
|||
} |
|||
} |
|||
//组装系统参数 |
|||
$sysParams["app_key"] = $this->appkey; |
|||
$sysParams["v"] = $this->apiVersion; |
|||
$sysParams["format"] = $this->format; |
|||
$sysParams["sign_method"] = $this->signMethod; |
|||
$sysParams["method"] = $request->getApiMethodName(); |
|||
$sysParams["timestamp"] = date("Y-m-d H:i:s"); |
|||
if (null != $session) |
|||
{ |
|||
$sysParams["session"] = $session; |
|||
} |
|||
|
|||
//获取业务参数 |
|||
$apiParams = $request->getApiParas(); |
|||
|
|||
|
|||
//系统参数放入GET请求串 |
|||
if($bestUrl){ |
|||
$requestUrl = $bestUrl."?"; |
|||
$sysParams["partner_id"] = $this->getClusterTag(); |
|||
}else{ |
|||
$requestUrl = $this->gatewayUrl."?"; |
|||
$sysParams["partner_id"] = $this->sdkVersion; |
|||
} |
|||
//签名 |
|||
$sysParams["sign"] = $this->generateSign(array_merge($apiParams, $sysParams)); |
|||
|
|||
foreach ($sysParams as $sysParamKey => $sysParamValue) |
|||
{ |
|||
// if(strcmp($sysParamKey,"timestamp") != 0) |
|||
$requestUrl .= "$sysParamKey=" . urlencode($sysParamValue) . "&"; |
|||
} |
|||
// $requestUrl .= "timestamp=" . urlencode($sysParams["timestamp"]) . "&"; |
|||
$requestUrl = substr($requestUrl, 0, -1); |
|||
|
|||
//发起HTTP请求 |
|||
try |
|||
{ |
|||
$resp = $this->curl($requestUrl, $apiParams); |
|||
} |
|||
catch (Exception $e) |
|||
{ |
|||
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_ERROR_" . $e->getCode(),$e->getMessage()); |
|||
$result->code = $e->getCode(); |
|||
$result->msg = $e->getMessage(); |
|||
return $result; |
|||
} |
|||
|
|||
//解析TOP返回结果 |
|||
$respWellFormed = false; |
|||
if ("json" == $this->format) |
|||
{ |
|||
$respObject = json_decode($resp); |
|||
if (null !== $respObject) |
|||
{ |
|||
$respWellFormed = true; |
|||
foreach ($respObject as $propKey => $propValue) |
|||
{ |
|||
$respObject = $propValue; |
|||
} |
|||
} |
|||
} |
|||
else if("xml" == $this->format) |
|||
{ |
|||
$respObject = @simplexml_load_string($resp); |
|||
if (false !== $respObject) |
|||
{ |
|||
$respWellFormed = true; |
|||
} |
|||
} |
|||
|
|||
//返回的HTTP文本不是标准JSON或者XML,记下错误日志 |
|||
if (false === $respWellFormed) |
|||
{ |
|||
$this->logCommunicationError($sysParams["method"],$requestUrl,"HTTP_RESPONSE_NOT_WELL_FORMED",$resp); |
|||
$result->code = 0; |
|||
$result->msg = "HTTP_RESPONSE_NOT_WELL_FORMED"; |
|||
return $result; |
|||
} |
|||
|
|||
//如果TOP返回了错误码,记录到业务错误日志中 |
|||
if (isset($respObject->code)) |
|||
{ |
|||
$logger = new TopLogger; |
|||
$logger->conf["log_file"] = rtrim(TOP_SDK_WORK_DIR, '\\/') . '/' . "logs/top_biz_err_" . $this->appkey . "_" . date("Y-m-d") . ".log"; |
|||
$logger->log(array( |
|||
date("Y-m-d H:i:s"), |
|||
$resp |
|||
)); |
|||
} |
|||
return $respObject; |
|||
} |
|||
|
|||
public function exec($paramsArray) |
|||
{ |
|||
if (!isset($paramsArray["method"])) |
|||
{ |
|||
trigger_error("No api name passed"); |
|||
} |
|||
$inflector = new LtInflector; |
|||
$inflector->conf["separator"] = "."; |
|||
$requestClassName = ucfirst($inflector->camelize(substr($paramsArray["method"], 7))) . "Request"; |
|||
if (!class_exists($requestClassName)) |
|||
{ |
|||
trigger_error("No such api: " . $paramsArray["method"]); |
|||
} |
|||
|
|||
$session = isset($paramsArray["session"]) ? $paramsArray["session"] : null; |
|||
|
|||
$req = new $requestClassName; |
|||
foreach($paramsArray as $paraKey => $paraValue) |
|||
{ |
|||
$inflector->conf["separator"] = "_"; |
|||
$setterMethodName = $inflector->camelize($paraKey); |
|||
$inflector->conf["separator"] = "."; |
|||
$setterMethodName = "set" . $inflector->camelize($setterMethodName); |
|||
if (method_exists($req, $setterMethodName)) |
|||
{ |
|||
$req->$setterMethodName($paraValue); |
|||
} |
|||
} |
|||
return $this->execute($req, $session); |
|||
} |
|||
|
|||
private function getClusterTag() |
|||
{ |
|||
return substr($this->sdkVersion,0,11)."-cluster".substr($this->sdkVersion,11); |
|||
} |
|||
} |
|||
class TopLogger |
|||
{ |
|||
public $conf = array( |
|||
"separator" => "\t", |
|||
"log_file" => "" |
|||
); |
|||
|
|||
private $fileHandle; |
|||
|
|||
protected function getFileHandle() |
|||
{ |
|||
if (null === $this->fileHandle) |
|||
{ |
|||
if (empty($this->conf["log_file"])) |
|||
{ |
|||
trigger_error("no log file spcified."); |
|||
} |
|||
$logDir = dirname($this->conf["log_file"]); |
|||
if (!is_dir($logDir)) |
|||
{ |
|||
mkdir($logDir, 0777, true); |
|||
} |
|||
$this->fileHandle = fopen($this->conf["log_file"], "a"); |
|||
} |
|||
return $this->fileHandle; |
|||
} |
|||
|
|||
public function log($logData) |
|||
{ |
|||
if ("" == $logData || array() == $logData) |
|||
{ |
|||
return false; |
|||
} |
|||
if (is_array($logData)) |
|||
{ |
|||
$logData = implode($this->conf["separator"], $logData); |
|||
} |
|||
$logData = $logData. "\n"; |
|||
fwrite($this->getFileHandle(), $logData); |
|||
} |
|||
} |
|||
class ResultSet |
|||
{ |
|||
|
|||
/** |
|||
* 返回的错误码 |
|||
**/ |
|||
public $code; |
|||
|
|||
/** |
|||
* 返回的错误信息 |
|||
**/ |
|||
public $msg; |
|||
|
|||
} |
|||
@ -0,0 +1,140 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
abstract class AcsRequest |
|||
{ |
|||
protected $version; |
|||
protected $product; |
|||
protected $actionName; |
|||
protected $regionId; |
|||
protected $acceptFormat; |
|||
protected $method; |
|||
protected $protocolType = "http"; |
|||
protected $content; |
|||
|
|||
protected $queryParameters = array(); |
|||
protected $headers = array(); |
|||
|
|||
function __construct($product, $version, $actionName) |
|||
{ |
|||
$this->headers["x-sdk-client"] = "php/2.0.0"; |
|||
$this->product = $product; |
|||
$this->version = $version; |
|||
$this->actionName = $actionName; |
|||
} |
|||
|
|||
public abstract function composeUrl($iSigner, $credential, $domain); |
|||
|
|||
public function getVersion() |
|||
{ |
|||
return $this->version; |
|||
} |
|||
|
|||
public function setVersion($version) |
|||
{ |
|||
$this->version = $version; |
|||
} |
|||
|
|||
public function getProduct() |
|||
{ |
|||
return $this->product; |
|||
} |
|||
|
|||
public function setProduct($product) |
|||
{ |
|||
$this->product = $product; |
|||
} |
|||
|
|||
public function getActionName() |
|||
{ |
|||
return $this->actionName; |
|||
} |
|||
|
|||
public function setActionName($actionName) |
|||
{ |
|||
$this->actionName = $actionName; |
|||
} |
|||
|
|||
public function getAcceptFormat() |
|||
{ |
|||
return $this->acceptFormat; |
|||
} |
|||
|
|||
public function setAcceptFormat($acceptFormat) |
|||
{ |
|||
$this->acceptFormat = $acceptFormat; |
|||
} |
|||
|
|||
public function getQueryParameters() |
|||
{ |
|||
return $this->queryParameters; |
|||
} |
|||
|
|||
public function getHeaders() |
|||
{ |
|||
return $this->headers; |
|||
} |
|||
|
|||
public function getMethod() |
|||
{ |
|||
return $this->method; |
|||
} |
|||
|
|||
public function setMethod($method) |
|||
{ |
|||
$this->method = $method; |
|||
} |
|||
|
|||
public function getProtocol() |
|||
{ |
|||
return $this->protocolType; |
|||
} |
|||
|
|||
public function setProtocol($protocol) |
|||
{ |
|||
$this->protocolType = $protocol; |
|||
} |
|||
|
|||
public function getRegionId() |
|||
{ |
|||
return $this->regionId; |
|||
} |
|||
public function setRegionId($region) |
|||
{ |
|||
$this->regionId = $region; |
|||
} |
|||
|
|||
public function getContent() |
|||
{ |
|||
return $this->content; |
|||
} |
|||
|
|||
public function setContent($content) |
|||
{ |
|||
$this->content = $content; |
|||
} |
|||
|
|||
|
|||
public function addHeader($headerKey, $headerValue) |
|||
{ |
|||
$this->headers[$headerKey] = $headerValue; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class AcsResponse |
|||
{ |
|||
private $code; |
|||
private $message; |
|||
|
|||
public function getCode() |
|||
{ |
|||
return $this->code; |
|||
} |
|||
|
|||
public function setCode($code) |
|||
{ |
|||
$this->code = $code; |
|||
} |
|||
|
|||
public function getMessage() |
|||
{ |
|||
return $this->message; |
|||
} |
|||
|
|||
public function setMessage($message) |
|||
{ |
|||
$this->message = $message; |
|||
} |
|||
} |
|||
@ -0,0 +1,87 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class Credential |
|||
{ |
|||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z'; |
|||
private $refreshDate; |
|||
private $expiredDate; |
|||
private $accessKeyId; |
|||
private $accessSecret; |
|||
private $securityToken; |
|||
|
|||
function __construct($accessKeyId, $accessSecret) |
|||
{ |
|||
$this->accessKeyId = $accessKeyId; |
|||
$this->accessSecret = $accessSecret; |
|||
$this->refreshDate = date($this->dateTimeFormat); |
|||
} |
|||
|
|||
public function isExpired() |
|||
{ |
|||
if($this->expiredDate == null) |
|||
{ |
|||
return false; |
|||
} |
|||
if(strtotime($this->expiredDate)>date($this->dateTimeFormat)) |
|||
{ |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
public function getRefreshDate() |
|||
{ |
|||
return $this->refreshDate; |
|||
} |
|||
|
|||
public function getExpiredDate() |
|||
{ |
|||
return $this->expiredDate; |
|||
} |
|||
|
|||
public function setExpiredDate($expiredHours) |
|||
{ |
|||
if($expiredHours>0) |
|||
{ |
|||
return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour")); |
|||
} |
|||
} |
|||
|
|||
public function getAccessKeyId() |
|||
{ |
|||
return $this->accessKeyId; |
|||
} |
|||
|
|||
public function setAccessKeyId($accessKeyId) |
|||
{ |
|||
$this->accessKeyId = $accessKeyId; |
|||
} |
|||
|
|||
public function getAccessSecret() |
|||
{ |
|||
return $this->accessSecret; |
|||
} |
|||
|
|||
public function setAccessSecret($accessSecret) |
|||
{ |
|||
$this->accessSecret = $accessSecret; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
interface ISigner |
|||
{ |
|||
public function getSignatureMethod(); |
|||
|
|||
public function getSignatureVersion(); |
|||
|
|||
public function signString($source, $accessSecret); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once 'ISigner.php'; |
|||
|
|||
class ShaHmac1Signer implements ISigner |
|||
{ |
|||
public function signString($source, $accessSecret) |
|||
{ |
|||
return base64_encode(hash_hmac('sha1', $source, $accessSecret, true)); |
|||
} |
|||
|
|||
public function getSignatureMethod() { |
|||
return "HMAC-SHA1"; |
|||
} |
|||
|
|||
public function getSignatureVersion() { |
|||
return "1.0"; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class ShaHmac256Signer implements ISigner |
|||
{ |
|||
public function signString($source, $accessSecret) |
|||
{ |
|||
return base64_encode(hash_hmac('sha256', $source, $accessSecret, true)); |
|||
} |
|||
|
|||
public function getSignatureMethod() { |
|||
return "HMAC-SHA256"; |
|||
} |
|||
|
|||
public function getSignatureVersion() { |
|||
return "1.0"; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,51 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
|
|||
spl_autoload_register("Autoloader::autoload", TRUE); |
|||
class Autoloader |
|||
{ |
|||
private static $autoloadPathArray = array( |
|||
"aliyun-php-sdk-core", |
|||
"aliyun-php-sdk-core/Auth", |
|||
"aliyun-php-sdk-core/Http", |
|||
"aliyun-php-sdk-core/Profile", |
|||
"aliyun-php-sdk-core/Regions", |
|||
"aliyun-php-sdk-core/Exception" |
|||
); |
|||
|
|||
public static function autoload($className) |
|||
{ |
|||
foreach (self::$autoloadPathArray as $path) { |
|||
$file = dirname(dirname(__DIR__)).DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$className.".php"; |
|||
$file = str_replace('\\', DIRECTORY_SEPARATOR, $file); |
|||
if(is_file($file)){ |
|||
include_once $file; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static function addAutoloadPath($path) |
|||
{ |
|||
array_push(self::$autoloadPathArray, $path); |
|||
} |
|||
} |
|||
|
|||
?> |
|||
@ -0,0 +1,50 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once dirname(__FILE__) . '/Autoloader/Autoloader.php'; |
|||
include_once dirname(__FILE__) . '/Regions/EndpointConfig.php'; |
|||
include_once dirname(__FILE__) . '/Profile/DefaultProfile.php'; |
|||
include_once dirname(__FILE__) . '/DefaultAcsClient.php'; |
|||
include_once dirname(__FILE__) . '/RpcAcsRequest.php'; |
|||
|
|||
|
|||
//config sdk auto load path. |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-ecs"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-batchcompute"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-sts"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-push"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-ram"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-ubsms"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-ubsms-inner"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-green"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-dm"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-iot"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-jaq"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-cs"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-live"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-vpc"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-kms"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-rds"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-slb"); |
|||
Autoloader::addAutoloadPath("aliyun-php-sdk-cms"); |
|||
|
|||
//config http proxy |
|||
define('ENABLE_HTTP_PROXY', FALSE); |
|||
define('HTTP_PROXY_IP', '127.0.0.1'); |
|||
define('HTTP_PROXY_PORT', '8888'); |
|||
@ -0,0 +1,139 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once dirname(__FILE__) . '/IAcsClient.php'; |
|||
include_once dirname(__FILE__) . '/Http/HttpHelper.php'; |
|||
include_once dirname(__FILE__) . '/Exception/ClientException.php'; |
|||
include_once dirname(__FILE__) . '/Exception/ServerException.php'; |
|||
|
|||
class DefaultAcsClient implements IAcsClient |
|||
{ |
|||
public $iClientProfile; |
|||
public $__urlTestFlag__; |
|||
|
|||
function __construct($iClientProfile) |
|||
{ |
|||
$this->iClientProfile = $iClientProfile; |
|||
$this->__urlTestFlag__ = false; |
|||
} |
|||
|
|||
public function getAcsResponse($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) |
|||
{ |
|||
$httpResponse = $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber); |
|||
$respObject = $this->parseAcsResponse($httpResponse->getBody(), $request->getAcceptFormat()); |
|||
if(false == $httpResponse->isSuccess()) |
|||
{ |
|||
$this->buildApiException($respObject, $httpResponse->getStatus()); |
|||
} |
|||
return $respObject; |
|||
} |
|||
|
|||
private function doActionImpl($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) |
|||
{ |
|||
if(null == $this->iClientProfile && (null == $iSigner || null == $credential |
|||
|| null == $request->getRegionId() || null == $request->getAcceptFormat())) |
|||
{ |
|||
throw new ClientException("No active profile found.", "SDK.InvalidProfile"); |
|||
} |
|||
if(null == $iSigner) |
|||
{ |
|||
$iSigner = $this->iClientProfile->getSigner(); |
|||
} |
|||
if(null == $credential) |
|||
{ |
|||
$credential = $this->iClientProfile->getCredential(); |
|||
} |
|||
$request = $this->prepareRequest($request); |
|||
$domain = EndpointProvider::findProductDomain($request->getRegionId(), $request->getProduct()); |
|||
if(null == $domain) |
|||
{ |
|||
throw new ClientException("Can not find endpoint to access.", "SDK.InvalidRegionId"); |
|||
} |
|||
$requestUrl = $request->composeUrl($iSigner, $credential, $domain); |
|||
|
|||
if ($this->__urlTestFlag__) { |
|||
throw new ClientException($requestUrl, "URLTestFlagIsSet"); |
|||
} |
|||
|
|||
if(count($request->getDomainParameter())>0){ |
|||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getDomainParameter(), $request->getHeaders()); |
|||
} else { |
|||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(),$request->getContent(), $request->getHeaders()); |
|||
} |
|||
|
|||
$retryTimes = 1; |
|||
while (500 <= $httpResponse->getStatus() && $autoRetry && $retryTimes < $maxRetryNumber) { |
|||
$requestUrl = $request->composeUrl($iSigner, $credential,$domain); |
|||
|
|||
if(count($request->getDomainParameter())>0){ |
|||
$httpResponse = HttpHelper::curl($requestUrl, $request->getDomainParameter(), $request->getHeaders()); |
|||
} else { |
|||
$httpResponse = HttpHelper::curl($requestUrl, $request->getMethod(), $request->getContent(), $request->getHeaders()); |
|||
} |
|||
$retryTimes ++; |
|||
} |
|||
return $httpResponse; |
|||
} |
|||
|
|||
public function doAction($request, $iSigner = null, $credential = null, $autoRetry = true, $maxRetryNumber = 3) |
|||
{ |
|||
trigger_error("doAction() is deprecated. Please use getAcsResponse() instead.", E_USER_NOTICE); |
|||
return $this->doActionImpl($request, $iSigner, $credential, $autoRetry, $maxRetryNumber); |
|||
} |
|||
|
|||
private function prepareRequest($request) |
|||
{ |
|||
if(null == $request->getRegionId()) |
|||
{ |
|||
$request->setRegionId($this->iClientProfile->getRegionId()); |
|||
} |
|||
if(null == $request->getAcceptFormat()) |
|||
{ |
|||
$request->setAcceptFormat($this->iClientProfile->getFormat()); |
|||
} |
|||
if(null == $request->getMethod()) |
|||
{ |
|||
$request->setMethod("GET"); |
|||
} |
|||
return $request; |
|||
} |
|||
|
|||
|
|||
private function buildApiException($respObject, $httpStatus) |
|||
{ |
|||
throw new ServerException($respObject->Message, $respObject->Code, $httpStatus, $respObject->RequestId); |
|||
} |
|||
|
|||
private function parseAcsResponse($body, $format) |
|||
{ |
|||
if ("JSON" == $format) |
|||
{ |
|||
$respObject = json_decode($body); |
|||
} |
|||
else if("XML" == $format) |
|||
{ |
|||
$respObject = @simplexml_load_string($body); |
|||
} |
|||
else if("RAW" == $format) |
|||
{ |
|||
$respObject = $body; |
|||
} |
|||
return $respObject; |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class ClientException extends Exception |
|||
{ |
|||
function __construct($errorMessage, $errorCode) |
|||
{ |
|||
parent::__construct($errorMessage); |
|||
$this->errorMessage = $errorMessage; |
|||
$this->errorCode = $errorCode; |
|||
$this->setErrorType("Client"); |
|||
} |
|||
|
|||
private $errorCode; |
|||
private $errorMessage; |
|||
private $errorType; |
|||
|
|||
public function getErrorCode() |
|||
{ |
|||
return $this->errorCode; |
|||
} |
|||
|
|||
public function setErrorCode($errorCode) |
|||
{ |
|||
$this->errorCode = $errorCode; |
|||
} |
|||
|
|||
public function getErrorMessage() |
|||
{ |
|||
return $this->errorMessage; |
|||
} |
|||
|
|||
public function setErrorMessage($errorMessage) |
|||
{ |
|||
$this->errorMessage = $errorMessage; |
|||
} |
|||
|
|||
public function getErrorType() |
|||
{ |
|||
return $this->errorType; |
|||
} |
|||
|
|||
public function setErrorType($errorType) |
|||
{ |
|||
$this->errorType = $errorType; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class ServerException extends ClientException |
|||
{ |
|||
private $httpStatus; |
|||
private $requestId; |
|||
|
|||
function __construct($errorMessage, $errorCode, $httpStatus, $requestId) |
|||
{ |
|||
$messageStr = $errorCode . " " . $errorMessage . " HTTP Status: " . $httpStatus . " RequestID: " . $requestId; |
|||
parent::__construct($messageStr, $errorCode); |
|||
$this->setErrorMessage($errorMessage); |
|||
$this->setErrorType("Server"); |
|||
$this->httpStatus = $httpStatus; |
|||
$this->requestId = $requestId; |
|||
} |
|||
|
|||
public function getHttpStatus() |
|||
{ |
|||
return $this->httpStatus; |
|||
} |
|||
|
|||
public function getRequestId() |
|||
{ |
|||
return $this->requestId; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,85 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once 'HttpResponse.php'; |
|||
|
|||
class HttpHelper |
|||
{ |
|||
public static $connectTimeout = 30;//30 second |
|||
public static $readTimeout = 80;//80 second |
|||
|
|||
public static function curl($url, $httpMethod = "GET", $postFields = null,$headers = null) |
|||
{ |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $httpMethod); |
|||
if(ENABLE_HTTP_PROXY) { |
|||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); |
|||
curl_setopt($ch, CURLOPT_PROXY, HTTP_PROXY_IP); |
|||
curl_setopt($ch, CURLOPT_PROXYPORT, HTTP_PROXY_PORT); |
|||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); |
|||
} |
|||
curl_setopt($ch, CURLOPT_URL, $url); |
|||
curl_setopt($ch, CURLOPT_FAILONERROR, false); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($postFields) ? self::getPostHttpBody($postFields) : $postFields); |
|||
|
|||
if (self::$readTimeout) { |
|||
curl_setopt($ch, CURLOPT_TIMEOUT, self::$readTimeout); |
|||
} |
|||
if (self::$connectTimeout) { |
|||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connectTimeout); |
|||
} |
|||
//https request |
|||
if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) { |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|||
} |
|||
if (is_array($headers) && 0 < count($headers)) |
|||
{ |
|||
$httpHeaders =self::getHttpHearders($headers); |
|||
curl_setopt($ch,CURLOPT_HTTPHEADER,$httpHeaders); |
|||
} |
|||
$httpResponse = new HttpResponse(); |
|||
$httpResponse->setBody(curl_exec($ch)); |
|||
$httpResponse->setStatus(curl_getinfo($ch, CURLINFO_HTTP_CODE)); |
|||
if (curl_errno($ch)) |
|||
{ |
|||
throw new ClientException("Server unreachable: Errno: " . curl_errno($ch) . " " . curl_error($ch), "SDK.ServerUnreachable"); |
|||
} |
|||
curl_close($ch); |
|||
return $httpResponse; |
|||
} |
|||
static function getPostHttpBody($postFildes){ |
|||
$content = ""; |
|||
foreach ($postFildes as $apiParamKey => $apiParamValue) |
|||
{ |
|||
$content .= "$apiParamKey=" . urlencode($apiParamValue) . "&"; |
|||
} |
|||
return substr($content, 0, -1); |
|||
} |
|||
static function getHttpHearders($headers) |
|||
{ |
|||
$httpHeader = array(); |
|||
foreach ($headers as $key => $value) |
|||
{ |
|||
array_push($httpHeader, $key.":".$value); |
|||
} |
|||
return $httpHeader; |
|||
} |
|||
} |
|||
@ -0,0 +1,53 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class HttpResponse |
|||
{ |
|||
private $body; |
|||
private $status; |
|||
|
|||
public function getBody() |
|||
{ |
|||
return $this->body; |
|||
} |
|||
|
|||
public function setBody($body) |
|||
{ |
|||
$this->body = $body; |
|||
} |
|||
|
|||
public function getStatus() |
|||
{ |
|||
return $this->status; |
|||
} |
|||
|
|||
public function setStatus($status) |
|||
{ |
|||
$this->status = $status; |
|||
} |
|||
|
|||
public function isSuccess() |
|||
{ |
|||
if(200 <= $this->status && 300 > $this->status) |
|||
{ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
interface IAcsClient |
|||
{ |
|||
public function doAction($requst); |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once dirname(__FILE__) . '/IClientProfile.php'; |
|||
include_once dirname(__FILE__) . '/../Auth/Credential.php'; |
|||
include_once dirname(__FILE__) . '/../Auth/ShaHmac1Signer.php'; |
|||
|
|||
class DefaultProfile implements IClientProfile |
|||
{ |
|||
private static $profile; |
|||
private static $endpoints; |
|||
private static $credential; |
|||
private static $regionId; |
|||
private static $acceptFormat; |
|||
|
|||
private static $isigner; |
|||
private static $iCredential; |
|||
|
|||
private function __construct($regionId,$credential) |
|||
{ |
|||
self::$regionId = $regionId; |
|||
self::$credential = $credential; |
|||
} |
|||
|
|||
public static function getProfile($regionId, $accessKeyId, $accessSecret) |
|||
{ |
|||
$credential =new Credential($accessKeyId, $accessSecret); |
|||
self::$profile = new DefaultProfile($regionId, $credential); |
|||
return self::$profile; |
|||
} |
|||
|
|||
public function getSigner() |
|||
{ |
|||
if(null == self::$isigner) |
|||
{ |
|||
self::$isigner = new ShaHmac1Signer(); |
|||
} |
|||
return self::$isigner; |
|||
} |
|||
|
|||
public function getRegionId() |
|||
{ |
|||
return self::$regionId; |
|||
} |
|||
|
|||
public function getFormat() |
|||
{ |
|||
return self::$acceptFormat; |
|||
} |
|||
|
|||
public function getCredential() |
|||
{ |
|||
if(null == self::$credential && null != self::$iCredential) |
|||
{ |
|||
self::$credential = self::$iCredential; |
|||
} |
|||
return self::$credential; |
|||
} |
|||
|
|||
public static function getEndpoints() |
|||
{ |
|||
if(null == self::$endpoints) |
|||
{ |
|||
self::$endpoints = EndpointProvider::getEndpoints(); |
|||
} |
|||
return self::$endpoints; |
|||
} |
|||
|
|||
public static function addEndpoint($endpointName, $regionId, $product, $domain) |
|||
{ |
|||
if(null == self::$endpoints) |
|||
{ |
|||
self::$endpoints = self::getEndpoints(); |
|||
} |
|||
$endpoint = self::findEndpointByName($endpointName); |
|||
if(null == $endpoint) |
|||
{ |
|||
self::addEndpoint_($endpointName, $regionId, $product, $domain); |
|||
} |
|||
else |
|||
{ |
|||
self::updateEndpoint($regionId, $product, $domain, $endpoint); |
|||
} |
|||
} |
|||
|
|||
public static function findEndpointByName($endpointName) |
|||
{ |
|||
foreach (self::$endpoints as $key => $endpoint) |
|||
{ |
|||
if($endpoint->getName() == $endpointName) |
|||
{ |
|||
return $endpoint; |
|||
} |
|||
} |
|||
} |
|||
|
|||
private static function addEndpoint_($endpointName,$regionId, $product, $domain) |
|||
{ |
|||
$regionIds = array($regionId); |
|||
$productsDomains = array(new ProductDomain($product, $domain)); |
|||
$endpoint = new Endpoint($endpointName, $regionIds, $productDomains); |
|||
array_push(self::$endpoints, $endpoint); |
|||
} |
|||
|
|||
private static function updateEndpoint($regionId, $product, $domain, $endpoint) |
|||
{ |
|||
$regionIds = $endpoint->getRegionIds(); |
|||
if(!in_array($regionId,$regionIds)) |
|||
{ |
|||
array_push($regionIds, $regionId); |
|||
$endpoint->setRegionIds($regionIds); |
|||
} |
|||
|
|||
$productDomains = $endpoint->getProductDomains(); |
|||
if(null == self::findProductDomain($productDomains, $product, $domain)) |
|||
{ |
|||
array_push($productDomains, new ProductDomain($product, $domain)); |
|||
} |
|||
$endpoint->setProductDomains($productDomains); |
|||
} |
|||
|
|||
private static function findProductDomain($productDomains, $product, $domain) |
|||
{ |
|||
foreach ($productDomains as $key => $productDomain) |
|||
{ |
|||
if($productDomain->getProductName() == $product && $productDomain->getDomainName() == $domain) |
|||
{ |
|||
return $productDomain; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
interface IClientProfile |
|||
{ |
|||
public function getSigner(); |
|||
|
|||
public function getRegionId(); |
|||
|
|||
public function getFormat(); |
|||
|
|||
public function getCredential(); |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class Endpoint |
|||
{ |
|||
private $name; |
|||
private $regionIds; |
|||
private $productDomains; |
|||
|
|||
function __construct($name, $regionIds, $productDomains) |
|||
{ |
|||
$this->name = $name; |
|||
$this->regionIds = $regionIds; |
|||
$this->productDomains = $productDomains; |
|||
} |
|||
|
|||
public function getName() |
|||
{ |
|||
return $this->name; |
|||
} |
|||
|
|||
public function setName($name) |
|||
{ |
|||
$this->name = $name; |
|||
} |
|||
|
|||
public function getRegionIds() |
|||
{ |
|||
return $this->regionIds; |
|||
} |
|||
|
|||
public function setRegionIds($regionIds) |
|||
{ |
|||
$this->regionIds = $regionIds; |
|||
} |
|||
|
|||
public function getProductDomains() |
|||
{ |
|||
return $this->productDomains; |
|||
} |
|||
|
|||
public function setProductDomains($productDomains) |
|||
{ |
|||
$this->productDomains = $productDomains; |
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "Endpoint.php"; |
|||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "EndpointProvider.php"; |
|||
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "ProductDomain.php"; |
|||
$endpoint_filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "endpoints.xml"; |
|||
$xml = simplexml_load_string(file_get_contents($endpoint_filename)); |
|||
$json = json_encode($xml); |
|||
$json_array = json_decode($json, TRUE); |
|||
|
|||
$endpoints = array(); |
|||
|
|||
foreach ($json_array["Endpoint"] as $json_endpoint) { |
|||
# pre-process RegionId & Product |
|||
if (!array_key_exists("RegionId", $json_endpoint["RegionIds"])) { |
|||
$region_ids = array(); |
|||
} else { |
|||
$json_region_ids = $json_endpoint['RegionIds']['RegionId']; |
|||
if (!is_array($json_region_ids)) { |
|||
$region_ids = array($json_region_ids); |
|||
} else { |
|||
$region_ids = $json_region_ids; |
|||
} |
|||
} |
|||
|
|||
if (!array_key_exists("Product", $json_endpoint["Products"])) { |
|||
$products = array(); |
|||
|
|||
} else { |
|||
$json_products = $json_endpoint["Products"]["Product"]; |
|||
|
|||
if (array() === $json_products or !is_array($json_products)) { |
|||
$products = array(); |
|||
} else if (array_keys($json_products) !== range(0, count($json_products) - 1)) { |
|||
# array is not sequential |
|||
$products = array($json_products); |
|||
} else { |
|||
$products = $json_products; |
|||
} |
|||
} |
|||
|
|||
$product_domains = array(); |
|||
foreach ($products as $product) { |
|||
$product_domain = new ProductDomain($product['ProductName'], $product['DomainName']); |
|||
array_push($product_domains, $product_domain); |
|||
} |
|||
|
|||
$endpoint = new Endpoint($region_ids[0], $region_ids, $product_domains); |
|||
array_push($endpoints, $endpoint); |
|||
} |
|||
|
|||
EndpointProvider::setEndpoints($endpoints); |
|||
@ -0,0 +1,67 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class EndpointProvider |
|||
{ |
|||
private static $endpoints; |
|||
|
|||
public static function findProductDomain($regionId, $product) |
|||
{ |
|||
if(null == $regionId || null == $product || null == self::$endpoints) |
|||
{ |
|||
return null; |
|||
} |
|||
foreach (self::$endpoints as $key => $endpoint) |
|||
{ |
|||
if(in_array($regionId, $endpoint->getRegionIds())) |
|||
{ |
|||
return self::findProductDomainByProduct($endpoint->getProductDomains(), $product); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
private static function findProductDomainByProduct($productDomains, $product) |
|||
{ |
|||
if(null == $productDomains) |
|||
{ |
|||
return null; |
|||
} |
|||
foreach ($productDomains as $key => $productDomain) |
|||
{ |
|||
if($product == $productDomain->getProductName()) |
|||
{ |
|||
return $productDomain->getDomainName(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
|
|||
public static function getEndpoints() |
|||
{ |
|||
return self::$endpoints; |
|||
} |
|||
|
|||
public static function setEndpoints($endpoints) |
|||
{ |
|||
self::$endpoints = $endpoints; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class ProductDomain |
|||
{ |
|||
private $productName; |
|||
private $domainName; |
|||
|
|||
function __construct($product, $domain) { |
|||
$this->productName = $product; |
|||
$this->domainName = $domain; |
|||
} |
|||
|
|||
public function getProductName() { |
|||
return $this->productName; |
|||
} |
|||
public function setProductName($productName) { |
|||
$this->productName = $productName; |
|||
} |
|||
public function getDomainName() { |
|||
return $this->domainName; |
|||
} |
|||
public function setDomainName($domainName) { |
|||
$this->domainName = $domainName; |
|||
} |
|||
|
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,223 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
abstract class RoaAcsRequest extends AcsRequest |
|||
{ |
|||
protected $uriPattern; |
|||
private $pathParameters = array(); |
|||
private $domainParameters = array(); |
|||
private $dateTimeFormat ="D, d M Y H:i:s \G\M\T"; |
|||
private static $headerSeparator = "\n"; |
|||
private static $querySeprator = "&"; |
|||
|
|||
function __construct($product, $version, $actionName) |
|||
{ |
|||
parent::__construct($product, $version, $actionName); |
|||
$this->setVersion($version); |
|||
$this->initialize(); |
|||
} |
|||
|
|||
private function initialize() |
|||
{ |
|||
$this->setMethod("RAW"); |
|||
} |
|||
|
|||
public function composeUrl($iSigner, $credential, $domain) |
|||
{ |
|||
$this->prepareHeader($iSigner); |
|||
|
|||
$signString = $this->getMethod().self::$headerSeparator; |
|||
if(isset($this->headers["Accept"])) |
|||
{ |
|||
$signString = $signString.$this->headers["Accept"]; |
|||
} |
|||
$signString = $signString.self::$headerSeparator; |
|||
|
|||
if(isset($this->headers["Content-MD5"])) |
|||
{ |
|||
$signString = $signString.$this->headers["Content-MD5"]; |
|||
} |
|||
$signString = $signString.self::$headerSeparator; |
|||
|
|||
if(isset($this->headers["Content-Type"])) |
|||
{ |
|||
$signString = $signString.$this->headers["Content-Type"]; |
|||
} |
|||
$signString = $signString.self::$headerSeparator; |
|||
|
|||
if(isset($this->headers["Date"])) |
|||
{ |
|||
$signString = $signString.$this->headers["Date"]; |
|||
} |
|||
$signString = $signString.self::$headerSeparator; |
|||
|
|||
$uri = $this->replaceOccupiedParameters(); |
|||
$signString = $signString.$this->buildCanonicalHeaders(); |
|||
$queryString = $this->buildQueryString($uri); |
|||
$signString .= $queryString; |
|||
$this->headers["Authorization"] = "acs ".$credential->getAccessKeyId().":" |
|||
.$iSigner->signString($signString, $credential->getAccessSecret()); |
|||
$requestUrl = $this->getProtocol()."://".$domain.$queryString; |
|||
return $requestUrl; |
|||
} |
|||
|
|||
private function prepareHeader($iSigner) |
|||
{ |
|||
date_default_timezone_set("GMT"); |
|||
$this->headers["Date"] = date($this->dateTimeFormat); |
|||
if(null == $this->acceptFormat) |
|||
{ |
|||
$this->acceptFormat = "RAW"; |
|||
} |
|||
$this->headers["Accept"] = $this->formatToAccept($this->getAcceptFormat()); |
|||
$this->headers["x-acs-signature-method"] = $iSigner->getSignatureMethod(); |
|||
$this->headers["x-acs-signature-version"] = $iSigner->getSignatureVersion(); |
|||
$this->headers["x-acs-region-id"] = $this->regionId; |
|||
$content = $this->getDomainParameter(); |
|||
if ($content != null) { |
|||
$this->headers["Content-MD5"] = base64_encode(md5(json_encode($content),true)); |
|||
} |
|||
$this->headers["Content-Type"] = "application/octet-stream;charset=utf-8"; |
|||
} |
|||
|
|||
private function replaceOccupiedParameters() |
|||
{ |
|||
$result = $this->uriPattern; |
|||
foreach ($this->pathParameters as $pathParameterKey => $apiParameterValue) |
|||
{ |
|||
$target = "[".$pathParameterKey."]"; |
|||
$result = str_replace($target,$apiParameterValue,$result); |
|||
} |
|||
return $result; |
|||
} |
|||
|
|||
private function buildCanonicalHeaders() |
|||
{ |
|||
$sortMap = array(); |
|||
foreach ($this->headers as $headerKey => $headerValue) |
|||
{ |
|||
$key = strtolower($headerKey); |
|||
if(strpos($key, "x-acs-") === 0) |
|||
{ |
|||
$sortMap[$key] = $headerValue; |
|||
} |
|||
} |
|||
ksort($sortMap); |
|||
$headerString = ""; |
|||
foreach ($sortMap as $sortMapKey => $sortMapValue) |
|||
{ |
|||
$headerString = $headerString.$sortMapKey.":".$sortMapValue.self::$headerSeparator; |
|||
} |
|||
return $headerString; |
|||
} |
|||
|
|||
private function splitSubResource($uri) |
|||
{ |
|||
$queIndex = strpos($uri, "?"); |
|||
$uriParts = array(); |
|||
if(null != $queIndex) |
|||
{ |
|||
array_push($uriParts, substr($uri,0,$queIndex)); |
|||
array_push($uriParts, substr($uri,$queIndex+1)); |
|||
} |
|||
else |
|||
{ |
|||
array_push($uriParts,$uri); |
|||
} |
|||
return $uriParts; |
|||
} |
|||
|
|||
private function buildQueryString($uri) |
|||
{ |
|||
$uriParts = $this->splitSubResource($uri); |
|||
$sortMap = $this->queryParameters; |
|||
if(isset($uriParts[1])) |
|||
{ |
|||
$sortMap[$uriParts[1]] = null; |
|||
} |
|||
$queryString = $uriParts[0]; |
|||
if(count($uriParts)) |
|||
{ |
|||
$queryString = $queryString."?"; |
|||
} |
|||
ksort($sortMap); |
|||
foreach ($sortMap as $sortMapKey => $sortMapValue) |
|||
{ |
|||
$queryString = $queryString.$sortMapKey; |
|||
if(isset($sortMapValue)) |
|||
{ |
|||
$queryString = $queryString."=".$sortMapValue; |
|||
} |
|||
$queryString = $queryString.$querySeprator; |
|||
} |
|||
if(null==count($sortMap)) |
|||
{ |
|||
$queryString = substr($queryString, 0, strlen($queryString)-1); |
|||
} |
|||
return $queryString; |
|||
} |
|||
|
|||
private function formatToAccept($acceptFormat) |
|||
{ |
|||
if($acceptFormat == "JSON") |
|||
{ |
|||
return "application/json"; |
|||
} |
|||
elseif ($acceptFormat == "XML") { |
|||
return "application/xml"; |
|||
} |
|||
return "application/octet-stream"; |
|||
} |
|||
|
|||
public function getPathParameters() |
|||
{ |
|||
return $this->pathParameters; |
|||
} |
|||
|
|||
public function putPathParameter($name, $value) |
|||
{ |
|||
$this->pathParameters[$name] = $value; |
|||
} |
|||
|
|||
public function getDomainParameter() |
|||
{ |
|||
return $this->domainParameters; |
|||
} |
|||
|
|||
public function putDomainParameters($name, $value) |
|||
{ |
|||
$this->domainParameters[$name] = $value; |
|||
} |
|||
|
|||
public function getUriPattern() |
|||
{ |
|||
return $this->uriPattern; |
|||
} |
|||
|
|||
public function setUriPattern($uriPattern) |
|||
{ |
|||
return $this->uriPattern = $uriPattern; |
|||
} |
|||
|
|||
public function setVersion($version) |
|||
{ |
|||
$this->version = $version; |
|||
$this->headers["x-acs-version"] = $version; |
|||
} |
|||
} |
|||
@ -0,0 +1,122 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once dirname(__FILE__) . '/AcsRequest.php'; |
|||
abstract class RpcAcsRequest extends AcsRequest |
|||
{ |
|||
private $dateTimeFormat = 'Y-m-d\TH:i:s\Z'; |
|||
private $domainParameters = array(); |
|||
|
|||
function __construct($product, $version, $actionName) |
|||
{ |
|||
parent::__construct($product, $version, $actionName); |
|||
$this->initialize(); |
|||
} |
|||
|
|||
private function initialize() |
|||
{ |
|||
$this->setMethod("GET"); |
|||
$this->setAcceptFormat("JSON"); |
|||
} |
|||
|
|||
|
|||
private function prepareValue($value) |
|||
{ |
|||
if (is_bool($value)) { |
|||
if ($value) { |
|||
return "true"; |
|||
} else { |
|||
return "false"; |
|||
} |
|||
} else { |
|||
return $value; |
|||
} |
|||
} |
|||
|
|||
public function composeUrl($iSigner, $credential, $domain) |
|||
{ |
|||
$apiParams = parent::getQueryParameters(); |
|||
foreach ($apiParams as $key => $value) { |
|||
$apiParams[$key] = $this->prepareValue($value); |
|||
} |
|||
$apiParams["RegionId"] = $this->getRegionId(); |
|||
$apiParams["AccessKeyId"] = $credential->getAccessKeyId(); |
|||
$apiParams["Format"] = $this->getAcceptFormat(); |
|||
$apiParams["SignatureMethod"] = $iSigner->getSignatureMethod(); |
|||
$apiParams["SignatureVersion"] = $iSigner->getSignatureVersion(); |
|||
$apiParams["SignatureNonce"] = uniqid(); |
|||
date_default_timezone_set("GMT"); |
|||
$apiParams["Timestamp"] = date($this->dateTimeFormat); |
|||
$apiParams["Action"] = $this->getActionName(); |
|||
$apiParams["Version"] = $this->getVersion(); |
|||
$apiParams["Signature"] = $this->computeSignature($apiParams, $credential->getAccessSecret(), $iSigner); |
|||
if(parent::getMethod() == "POST") { |
|||
|
|||
$requestUrl = $this->getProtocol()."://". $domain . "/"; |
|||
foreach ($apiParams as $apiParamKey => $apiParamValue) |
|||
{ |
|||
$this->putDomainParameters($apiParamKey,$apiParamValue); |
|||
} |
|||
return $requestUrl; |
|||
} |
|||
else { |
|||
$requestUrl = $this->getProtocol()."://". $domain . "/?"; |
|||
|
|||
foreach ($apiParams as $apiParamKey => $apiParamValue) |
|||
{ |
|||
$requestUrl .= "$apiParamKey=" . urlencode($apiParamValue) . "&"; |
|||
} |
|||
return substr($requestUrl, 0, -1); |
|||
} |
|||
} |
|||
|
|||
private function computeSignature($parameters, $accessKeySecret, $iSigner) |
|||
{ |
|||
ksort($parameters); |
|||
$canonicalizedQueryString = ''; |
|||
foreach($parameters as $key => $value) |
|||
{ |
|||
$canonicalizedQueryString .= '&' . $this->percentEncode($key). '=' . $this->percentEncode($value); |
|||
} |
|||
$stringToSign = parent::getMethod().'&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1)); |
|||
$signature = $iSigner->signString($stringToSign, $accessKeySecret."&"); |
|||
|
|||
return $signature; |
|||
} |
|||
|
|||
protected function percentEncode($str) |
|||
{ |
|||
$res = urlencode($str); |
|||
$res = preg_replace('/\+/', '%20', $res); |
|||
$res = preg_replace('/\*/', '%2A', $res); |
|||
$res = preg_replace('/%7E/', '~', $res); |
|||
return $res; |
|||
} |
|||
|
|||
public function getDomainParameter() |
|||
{ |
|||
return $this->domainParameters; |
|||
} |
|||
|
|||
public function putDomainParameters($name, $value) |
|||
{ |
|||
$this->domainParameters[$name] = $value; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../../Config.php'; |
|||
class CredentialTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public function testCredential() |
|||
{ |
|||
$credential = new Credential("accessKeyId", "accessSecret"); |
|||
$this->assertEquals("accessKeyId",$credential->getAccessKeyId()); |
|||
$this->assertEquals("accessSecret",$credential->getAccessSecret()); |
|||
$this->assertNotNull($credential->getRefreshDate()); |
|||
|
|||
$dateNow = date("Y-m-d\TH:i:s\Z"); |
|||
$credential->setExpiredDate(1); |
|||
$this->assertNotNull($credential->getExpiredDate()); |
|||
$this->assertTrue($credential->getExpiredDate() > $dateNow); |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../../Config.php'; |
|||
class ShaHmac1SignerTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public function testShaHmac1Signer() |
|||
{ |
|||
$signer = new ShaHmac1Signer(); |
|||
$this->assertEquals("33nmIV5/p6kG/64eLXNljJ5vw84=",$signer->signString("this is a ShaHmac1 test.", "accessSecret")); |
|||
} |
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../../Config.php'; |
|||
|
|||
class ShaHmac256SignerTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public function testShaHmac256Signer() |
|||
{ |
|||
$signer = new ShaHmac256Signer(); |
|||
$this->assertEquals("TpF1lE/avV9EHGWGg9Vo/QTd2bLRwFCk9jjo56uRbCo=", |
|||
$signer->signString("this is a ShaHmac256 test.", "accessSecret")); |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
class BaseTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public $client = null; |
|||
function setUp() |
|||
{ |
|||
$path = substr(dirname(__FILE__), 0,strripos(dirname(__FILE__),DIRECTORY_SEPARATOR)).DIRECTORY_SEPARATOR; |
|||
include_once $path.'Config.php'; |
|||
include_once 'Ecs/Rquest/DescribeRegionsRequest.php'; |
|||
include_once 'BatchCompute/ListImagesRequest.php'; |
|||
|
|||
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret"); |
|||
$this->client = new DefaultAcsClient($iClientProfile); |
|||
} |
|||
|
|||
function getProperty($propertyKey) |
|||
{ |
|||
$accessKey = ""; |
|||
$accessSecret = ""; |
|||
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", "AccessKey", "AccessSecret"); |
|||
|
|||
|
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
namespace UnitTest\BatchCompute\Request; |
|||
|
|||
class ListImagesRequest extends \RoaAcsRequest |
|||
{ |
|||
function __construct() |
|||
{ |
|||
parent::__construct("BatchCompute", "2013-01-11", "ListImages"); |
|||
$this->setUriPattern("/images"); |
|||
$this->setMethod("GET"); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once 'BaseTest.php'; |
|||
use UnitTest\Ecs\Request as Ecs; |
|||
use UnitTest\BatchCompute\Request as BC; |
|||
|
|||
class DefaultAcsClientTest extends BaseTest |
|||
{ |
|||
public function testDoActionRPC() |
|||
{ |
|||
$request = new Ecs\DescribeRegionsRequest(); |
|||
$response = $this->client->doAction($request); |
|||
|
|||
$this->assertNotNull($response->RequestId); |
|||
$this->assertNotNull($response->Regions->Region[0]->LocalName); |
|||
$this->assertNotNull($response->Regions->Region[0]->RegionId); |
|||
} |
|||
|
|||
public function testDoActionROA() |
|||
{ |
|||
$request = new BC\ListImagesRequest(); |
|||
$response = $this->client->doAction($request); |
|||
$this->assertNotNull($response); |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
namespace UnitTest\Ecs\Request; |
|||
|
|||
class DescribeRegionsRequest extends \RpcAcsRequest |
|||
{ |
|||
function __construct() |
|||
{ |
|||
parent::__construct("Ecs", "2014-05-26", "DescribeRegions"); |
|||
} |
|||
|
|||
private $ownerId; |
|||
|
|||
private $resourceOwnerAccount; |
|||
|
|||
private $resourceOwnerId; |
|||
|
|||
private $ownerAccount; |
|||
|
|||
public function getOwnerId() { |
|||
return $this->ownerId; |
|||
} |
|||
|
|||
public function setOwnerId($ownerId) { |
|||
$this->ownerId = $ownerId; |
|||
$this->queryParameters["OwnerId"]=$ownerId; |
|||
} |
|||
|
|||
public function getResourceOwnerAccount() { |
|||
return $this->resourceOwnerAccount; |
|||
} |
|||
|
|||
public function setResourceOwnerAccount($resourceOwnerAccount) { |
|||
$this->resourceOwnerAccount = $resourceOwnerAccount; |
|||
$this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount; |
|||
} |
|||
|
|||
public function getResourceOwnerId() { |
|||
return $this->resourceOwnerId; |
|||
} |
|||
|
|||
public function setResourceOwnerId($resourceOwnerId) { |
|||
$this->resourceOwnerId = $resourceOwnerId; |
|||
$this->queryParameters["ResourceOwnerId"]=$resourceOwnerId; |
|||
} |
|||
|
|||
public function getOwnerAccount() { |
|||
return $this->ownerAccount; |
|||
} |
|||
|
|||
public function setOwnerAccount($ownerAccount) { |
|||
$this->ownerAccount = $ownerAccount; |
|||
$this->queryParameters["OwnerAccount"]=$ownerAccount; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../BaseTest.php'; |
|||
class HttpHelperTest extends BaseTest |
|||
{ |
|||
public function testCurl() |
|||
{ |
|||
$httpResponse = HttpHelper::curl("ecs.aliyuncs.com"); |
|||
$this->assertEquals(400,$httpResponse->getStatus()); |
|||
$this->assertNotNull($httpResponse->getBody()); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../../Config.php'; |
|||
class DefaultProfileTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
public function testGetProfile() |
|||
{ |
|||
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret"); |
|||
$this->assertEquals("cn-hangzhou",$profile->getRegionId()); |
|||
$this->assertEquals("accessId",$profile->getCredential()->getAccessKeyId()); |
|||
$this->assertEquals("accessSecret",$profile->getCredential()->getAccessSecret()); |
|||
} |
|||
|
|||
public function testAddEndpoint() |
|||
{ |
|||
$profile = DefaultProfile::getProfile("cn-hangzhou", "accessId", "accessSecret"); |
|||
$profile->addEndpoint("cn-hangzhou", "cn-hangzhou", "TestProduct", "testproduct.aliyuncs.com"); |
|||
$endpoints = $profile->getEndpoints(); |
|||
foreach ($endpoints as $key => $endpoint) |
|||
{ |
|||
if("cn-hangzhou" == $endpoint->getName()) |
|||
{ |
|||
$regionIds = $endpoint->getRegionIds(); |
|||
$this->assertContains("cn-hangzhou",$regionIds); |
|||
|
|||
$productDomains= $endpoint->getProductDomains(); |
|||
$this->assertNotNull($productDomains); |
|||
$productDomain = $this->getProductDomain($productDomains); |
|||
$this->assertNotNull($productDomain); |
|||
$this->assertEquals("TestProduct",$productDomain->getProductName()); |
|||
$this->assertEquals("testproduct.aliyuncs.com",$productDomain->getDomainName()); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private function getProductDomain($productDomains) |
|||
{ |
|||
foreach ($productDomains as $productDomain) |
|||
{ |
|||
if($productDomain->getProductName() == "TestProduct") |
|||
{ |
|||
return $productDomain; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
include_once '../../Config.php'; |
|||
|
|||
class EndpointProviderTest extends PHPUnit_Framework_TestCase |
|||
{ |
|||
|
|||
public function testFindProductDomain() |
|||
{ |
|||
$this->assertEquals("ecs.aliyuncs.com",EndpointProvider::findProductDomain("cn-hangzhou", "Ecs")); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,116 @@ |
|||
<?php |
|||
/* |
|||
* Licensed to the Apache Software Foundation (ASF) under one |
|||
* or more contributor license agreements. See the NOTICE file |
|||
* distributed with this work for additional information |
|||
* regarding copyright ownership. The ASF licenses this file |
|||
* to you under the Apache License, Version 2.0 (the |
|||
* "License"); you may not use this file except in compliance |
|||
* with the License. You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, |
|||
* software distributed under the License is distributed on an |
|||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|||
* KIND, either express or implied. See the License for the |
|||
* specific language governing permissions and limitations |
|||
* under the License. |
|||
*/ |
|||
|
|||
class Sendsmsrequest extends RpcAcsRequest |
|||
{ |
|||
function __construct() |
|||
{ |
|||
parent::__construct("Dysmsapi", "2017-05-25", "SendSms"); |
|||
} |
|||
|
|||
private $outId; |
|||
|
|||
private $signName; |
|||
|
|||
private $ownerId; |
|||
|
|||
private $resourceOwnerId; |
|||
|
|||
private $templateCode; |
|||
|
|||
private $phoneNumbers; |
|||
|
|||
private $resourceOwnerAccount; |
|||
|
|||
private $templateParam; |
|||
|
|||
public function getOutId() { |
|||
return $this->outId; |
|||
} |
|||
|
|||
public function setOutId($outId) { |
|||
$this->outId = $outId; |
|||
$this->queryParameters["OutId"]=$outId; |
|||
} |
|||
|
|||
public function getSignName() { |
|||
return $this->signName; |
|||
} |
|||
|
|||
public function setSignName($signName) { |
|||
$this->signName = $signName; |
|||
$this->queryParameters["SignName"]=$signName; |
|||
} |
|||
|
|||
public function getOwnerId() { |
|||
return $this->ownerId; |
|||
} |
|||
|
|||
public function setOwnerId($ownerId) { |
|||
$this->ownerId = $ownerId; |
|||
$this->queryParameters["OwnerId"]=$ownerId; |
|||
} |
|||
|
|||
public function getResourceOwnerId() { |
|||
return $this->resourceOwnerId; |
|||
} |
|||
|
|||
public function setResourceOwnerId($resourceOwnerId) { |
|||
$this->resourceOwnerId = $resourceOwnerId; |
|||
$this->queryParameters["ResourceOwnerId"]=$resourceOwnerId; |
|||
} |
|||
|
|||
public function getTemplateCode() { |
|||
return $this->templateCode; |
|||
} |
|||
|
|||
public function setTemplateCode($templateCode) { |
|||
$this->templateCode = $templateCode; |
|||
$this->queryParameters["TemplateCode"]=$templateCode; |
|||
} |
|||
|
|||
public function getPhoneNumbers() { |
|||
return $this->phoneNumbers; |
|||
} |
|||
|
|||
public function setPhoneNumbers($phoneNumbers) { |
|||
$this->phoneNumbers = $phoneNumbers; |
|||
$this->queryParameters["PhoneNumbers"]=$phoneNumbers; |
|||
} |
|||
|
|||
public function getResourceOwnerAccount() { |
|||
return $this->resourceOwnerAccount; |
|||
} |
|||
|
|||
public function setResourceOwnerAccount($resourceOwnerAccount) { |
|||
$this->resourceOwnerAccount = $resourceOwnerAccount; |
|||
$this->queryParameters["ResourceOwnerAccount"]=$resourceOwnerAccount; |
|||
} |
|||
|
|||
public function getTemplateParam() { |
|||
return $this->templateParam; |
|||
} |
|||
|
|||
public function setTemplateParam($templateParam) { |
|||
$this->templateParam = $templateParam; |
|||
$this->queryParameters["TemplateParam"]=$templateParam; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,117 @@ |
|||
<?php |
|||
class model_pay |
|||
{ |
|||
|
|||
function wechat_build($params, $wechat, $notify_url='') { |
|||
global $_W; |
|||
load()->func('communication'); |
|||
if(empty($notify_url)) $notify_url = $_W['siteroot'] . 'payment/wechat/notify.php'; |
|||
if (empty($wechat['version']) && !empty($wechat['signkey'])) { |
|||
$wechat['version'] = 1; |
|||
} |
|||
$wOpt = array(); |
|||
if ($wechat['version'] == 1) { |
|||
$wOpt['appId'] = $wechat['appid']; |
|||
$wOpt['timeStamp'] = TIMESTAMP; |
|||
$wOpt['nonceStr'] = random(8); |
|||
$package = array(); |
|||
$package['bank_type'] = 'WX'; |
|||
$package['body'] = $params['title']; |
|||
$package['attach'] = $_W['uniacid']; |
|||
$package['partner'] = $wechat['partner']; |
|||
$package['out_trade_no'] = $params['uniontid']; |
|||
$package['total_fee'] = $params['fee'] * 100; |
|||
$package['fee_type'] = '1'; |
|||
$package['notify_url'] = $notify_url; |
|||
$package['spbill_create_ip'] = CLIENT_IP; |
|||
$package['time_start'] = date('YmdHis', TIMESTAMP); |
|||
$package['time_expire'] = date('YmdHis', TIMESTAMP + 600); |
|||
$package['input_charset'] = 'UTF-8'; |
|||
ksort($package); |
|||
$string1 = ''; |
|||
foreach($package as $key => $v) { |
|||
if (empty($v)) { |
|||
continue; |
|||
} |
|||
$string1 .= "{$key}={$v}&"; |
|||
} |
|||
$string1 .= "key={$wechat['key']}"; |
|||
$sign = strtoupper(md5($string1)); |
|||
|
|||
$string2 = ''; |
|||
foreach($package as $key => $v) { |
|||
$v = urlencode($v); |
|||
$string2 .= "{$key}={$v}&"; |
|||
} |
|||
$string2 .= "sign={$sign}"; |
|||
$wOpt['package'] = $string2; |
|||
|
|||
$string = ''; |
|||
$keys = array('appId', 'timeStamp', 'nonceStr', 'package', 'appKey'); |
|||
sort($keys); |
|||
foreach($keys as $key) { |
|||
$v = $wOpt[$key]; |
|||
if($key == 'appKey') { |
|||
$v = $wechat['signkey']; |
|||
} |
|||
$key = strtolower($key); |
|||
$string .= "{$key}={$v}&"; |
|||
} |
|||
$string = rtrim($string, '&'); |
|||
|
|||
$wOpt['signType'] = 'SHA1'; |
|||
$wOpt['paySign'] = sha1($string); |
|||
return $wOpt; |
|||
} else { |
|||
$package = array(); |
|||
$package['appid'] = $wechat['appid']; |
|||
$package['mch_id'] = $wechat['mchid']; |
|||
$package['nonce_str'] = random(8); |
|||
$package['body'] = $params['title']; |
|||
$package['attach'] = $_W['uniacid']; |
|||
$package['out_trade_no'] = $params['uniontid']; |
|||
$package['total_fee'] = $params['fee'] * 100; |
|||
$package['spbill_create_ip'] = CLIENT_IP; |
|||
$package['time_start'] = date('YmdHis', TIMESTAMP); |
|||
$package['time_expire'] = date('YmdHis', TIMESTAMP + 600); |
|||
$package['notify_url'] = $notify_url; |
|||
$package['trade_type'] = 'JSAPI'; |
|||
$package['openid'] = $_W['fans']['from_user']; |
|||
ksort($package, SORT_STRING); |
|||
$string1 = ''; |
|||
foreach($package as $key => $v) { |
|||
if (empty($v)) { |
|||
continue; |
|||
} |
|||
$string1 .= "{$key}={$v}&"; |
|||
} |
|||
$string1 .= "key={$wechat['signkey']}"; |
|||
$package['sign'] = strtoupper(md5($string1)); |
|||
$dat = array2xml($package); |
|||
$response = ihttp_request('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat); |
|||
if (is_error($response)) { |
|||
return $response; |
|||
} |
|||
$xml = @isimplexml_load_string($response['content'], 'SimpleXMLElement', LIBXML_NOCDATA); |
|||
if (strval($xml->return_code) == 'FAIL') { |
|||
return error(-1, strval($xml->return_msg)); |
|||
} |
|||
if (strval($xml->result_code) == 'FAIL') { |
|||
return error(-1, strval($xml->err_code).': '.strval($xml->err_code_des)); |
|||
} |
|||
$prepayid = $xml->prepay_id; |
|||
$wOpt['appId'] = $wechat['appid']; |
|||
$wOpt['timeStamp'] = TIMESTAMP; |
|||
$wOpt['nonceStr'] = random(8); |
|||
$wOpt['package'] = 'prepay_id='.$prepayid; |
|||
$wOpt['signType'] = 'MD5'; |
|||
ksort($wOpt, SORT_STRING); |
|||
foreach($wOpt as $key => $v) { |
|||
$string .= "{$key}={$v}&"; |
|||
} |
|||
$string .= "key={$wechat['signkey']}"; |
|||
$wOpt['paySign'] = strtoupper(md5($string)); |
|||
return $wOpt; |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,425 @@ |
|||
<?php |
|||
|
|||
namespace QL; |
|||
|
|||
require 'phpQuery.php'; |
|||
|
|||
use phpQuery,Exception,ReflectionClass; |
|||
|
|||
/** |
|||
* QueryList |
|||
* |
|||
* 一个基于phpQuery的通用列表采集类 |
|||
* |
|||
* @author Jaeger |
|||
* @email 734708094@qq.com |
|||
* @link http://git.oschina.net/jae/QueryList |
|||
* @version 3.1.2 |
|||
* |
|||
* @example |
|||
* |
|||
//获取CSDN移动开发栏目下的文章列表标题 |
|||
$hj = QueryList::Query('http://mobile.csdn.net/',array("title"=>array('.unit h1','text'))); |
|||
print_r($hj->data); |
|||
|
|||
//回调函数1 |
|||
function callfun1($content,$key) |
|||
{ |
|||
return '回调函数1:'.$key.'-'.$content; |
|||
} |
|||
class HJ{ |
|||
//回调函数2 |
|||
static public function callfun2($content,$key) |
|||
{ |
|||
return '回调函数2:'.$key.'-'.$content; |
|||
} |
|||
} |
|||
//获取CSDN文章页下面的文章标题和内容 |
|||
$url = 'http://www.csdn.net/article/2014-06-05/2820091-build-or-buy-a-mobile-game-backend'; |
|||
$rules = array( |
|||
'title'=>array('h1','text','','callfun1'), //获取纯文本格式的标题,并调用回调函数1 |
|||
'summary'=>array('.summary','text','-input strong'), //获取纯文本的文章摘要,但保strong标签并去除input标签 |
|||
'content'=>array('.news_content','html','div a -.copyright'), //获取html格式的文章内容,但过滤掉div和a标签,去除类名为copyright的元素 |
|||
'callback'=>array('HJ','callfun2') //调用回调函数2作为全局回调函数 |
|||
); |
|||
$rang = '.left'; |
|||
$hj = QueryList::Query($url,$rules,$rang); |
|||
print_r($hj->data); |
|||
|
|||
//继续获取右边相关热门文章列表的标题以及链接地址 |
|||
$hj->setQuery(array('title'=>array('','text'),'url'=>array('a','href')),'#con_two_2 li'); |
|||
//输出数据 |
|||
echo $hj->getData(); |
|||
|
|||
*/ |
|||
|
|||
class QueryList |
|||
{ |
|||
public $data; |
|||
public $html; |
|||
private $pqHtml; |
|||
private $outputEncoding = false; |
|||
private $inputEncoding = false; |
|||
private $htmlEncoding; |
|||
public static $instances; |
|||
|
|||
public function __construct() { |
|||
} |
|||
/** |
|||
* 静态方法,访问入口 |
|||
* @param string $page 要抓取的网页URL地址(支持https);或者是html源代码 |
|||
* @param array $rules 【选择器数组】说明:格式array("名称"=>array("选择器","类型"[,"标签过滤列表"][,"回调函数"]),.......[,"callback"=>"全局回调函数"]); |
|||
* 【选择器】说明:可以为任意的jQuery选择器语法 |
|||
* 【类型】说明:值 "text" ,"html" ,"HTML标签属性" , |
|||
* 【标签过滤列表】:可选,要过滤的选择器名,多个用空格隔开,当标签名前面添加减号(-)时(此时标签可以为任意的元素选择器),表示移除该标签以及标签内容,否则当【类型】值为text时表示需要保留的HTML标签,为html时表示要过滤掉的HTML标签 |
|||
* 【回调函数】/【全局回调函数】:可选,字符串(函数名) 或 数组(array("类名","类的静态方法")),回调函数应有俩个参数,第一个参数是选择到的内容,第二个参数是选择器数组下标,回调函数会覆盖全局回调函数 |
|||
* |
|||
* @param string $range 【块选择器】:指 先按照规则 选出 几个大块 ,然后再分别再在块里面 进行相关的选择 |
|||
* @param string $outputEncoding【输出编码格式】指要以什么编码输出(UTF-8,GB2312,.....),防止出现乱码,如果设置为 假值 则不改变原字符串编码 |
|||
* @param string $inputEncoding 【输入编码格式】明确指定输入的页面编码格式(UTF-8,GB2312,.....),防止出现乱码,如果设置为 假值 则自动识别 |
|||
* @param bool|false $removeHead 【是否移除页面头部区域】 乱码终极解决方案 |
|||
* @return mixed |
|||
*/ |
|||
public static function Query($page,array $rules, $range = '', $outputEncoding = null, $inputEncoding = null,$removeHead = false) |
|||
{ |
|||
return self::getInstance()->_query($page, $rules, $range, $outputEncoding, $inputEncoding,$removeHead); |
|||
} |
|||
|
|||
/** |
|||
* 运行QueryList扩展 |
|||
* @param $class |
|||
* @param array $args |
|||
* @return mixed |
|||
* @throws Exception |
|||
*/ |
|||
public static function run($class,$args = array()) |
|||
{ |
|||
$extension = self::getInstance("QL\\Ext\\{$class}"); |
|||
return $extension->run($args); |
|||
} |
|||
|
|||
/** |
|||
* 获取任意实例 |
|||
* @return mixed |
|||
* @throws Exception |
|||
*/ |
|||
public static function getInstance() |
|||
{ |
|||
$args = func_get_args(); |
|||
count($args) || $args = array('QL\QueryList'); |
|||
$key = md5(serialize($args)); |
|||
$className = array_shift($args); |
|||
if(!class_exists($className)) { |
|||
throw new Exception("no class {$className}"); |
|||
} |
|||
if(!isset(self::$instances[$key])) { |
|||
$rc = new ReflectionClass($className); |
|||
self::$instances[$key] = $rc->newInstanceArgs($args); |
|||
} |
|||
return self::$instances[$key]; |
|||
} |
|||
|
|||
/** |
|||
* 获取目标页面源码(主要用于调试) |
|||
* @param bool|true $rel |
|||
* @return string |
|||
*/ |
|||
public function getHtml($rel = true) |
|||
{ |
|||
return $rel?$this->qpHtml:$this->html; |
|||
} |
|||
|
|||
/** |
|||
* 获取采集结果数据 |
|||
* @param callback $callback |
|||
* @return array |
|||
*/ |
|||
public function getData($callback = null) |
|||
{ |
|||
if(is_callable($callback)){ |
|||
return array_map($callback,$this->data); |
|||
} |
|||
return $this->data; |
|||
} |
|||
|
|||
/** |
|||
* 重新设置选择器 |
|||
* @param $rules |
|||
* @param string $range |
|||
* @param string $outputEncoding |
|||
* @param string $inputEncoding |
|||
* @param bool|false $removeHead |
|||
* @return QueryList |
|||
*/ |
|||
public function setQuery(array $rules, $range = '',$outputEncoding = null, $inputEncoding = null,$removeHead = false) |
|||
{ |
|||
return $this->_query($this->html,$rules, $range, $outputEncoding, $inputEncoding,$removeHead); |
|||
} |
|||
|
|||
private function _query($page,array $rules, $range, $outputEncoding, $inputEncoding,$removeHead) |
|||
{ |
|||
$this->data = array(); |
|||
$this->html = $this->_isURL($page)?$this->_request($page):$page; |
|||
$outputEncoding && $this->outputEncoding = $outputEncoding; |
|||
$inputEncoding && $this->inputEncoding = $inputEncoding; |
|||
$removeHead && $this->html = $this->_removeHead($this->html); |
|||
$this->pqHtml = ''; |
|||
if(empty($this->html)){ |
|||
trigger_error("The received content is empty!",E_USER_NOTICE); |
|||
} |
|||
//获取编码格式 |
|||
$this->htmlEncoding = $this->inputEncoding?$this->inputEncoding:$this->_getEncode($this->html); |
|||
// $this->html = $this->_removeTags($this->html,array('script','style')); |
|||
$this->regArr = $rules; |
|||
$this->regRange = $range; |
|||
$this->_getList(); |
|||
return $this; |
|||
} |
|||
|
|||
private function _getList() |
|||
{ |
|||
$this->inputEncoding && phpQuery::$defaultCharset = $this->inputEncoding; |
|||
$document = phpQuery::newDocumentHTML($this->html); |
|||
$this->qpHtml = $document->htmlOuter(); |
|||
if (!empty($this->regRange)) { |
|||
$robj = pq($document)->find($this->regRange); |
|||
$i = 0; |
|||
foreach ($robj as $item) { |
|||
while (list($key, $reg_value) = each($this->regArr)) { |
|||
if($key=='callback')continue; |
|||
$tags = isset($reg_value[2])?$reg_value[2]:''; |
|||
$iobj = pq($item)->find($reg_value[0]); |
|||
|
|||
switch ($reg_value[1]) { |
|||
case 'text': |
|||
$this->data[$i][$key] = $this->_allowTags(pq($iobj)->html(),$tags); |
|||
break; |
|||
case 'html': |
|||
$this->data[$i][$key] = $this->_stripTags(pq($iobj)->html(),$tags); |
|||
break; |
|||
default: |
|||
$this->data[$i][$key] = pq($iobj)->attr($reg_value[1]); |
|||
break; |
|||
} |
|||
|
|||
if(isset($reg_value[3])){ |
|||
$this->data[$i][$key] = call_user_func($reg_value[3],$this->data[$i][$key],$key); |
|||
}else if(isset($this->regArr['callback'])){ |
|||
$this->data[$i][$key] = call_user_func($this->regArr['callback'],$this->data[$i][$key],$key); |
|||
} |
|||
} |
|||
//重置数组指针 |
|||
reset($this->regArr); |
|||
$i++; |
|||
} |
|||
} else { |
|||
while (list($key, $reg_value) = each($this->regArr)) { |
|||
if($key=='callback')continue; |
|||
$document = phpQuery::newDocumentHTML($this->html); |
|||
$tags = isset($reg_value[2])?$reg_value[2]:''; |
|||
$lobj = pq($document)->find($reg_value[0]); |
|||
$i = 0; |
|||
foreach ($lobj as $item) { |
|||
switch ($reg_value[1]) { |
|||
case 'text': |
|||
$this->data[$i][$key] = $this->_allowTags(pq($item)->html(),$tags); |
|||
break; |
|||
case 'html': |
|||
$this->data[$i][$key] = $this->_stripTags(pq($item)->html(),$tags); |
|||
break; |
|||
default: |
|||
$this->data[$i][$key] = pq($item)->attr($reg_value[1]); |
|||
break; |
|||
} |
|||
|
|||
if(isset($reg_value[3])){ |
|||
$this->data[$i][$key] = call_user_func($reg_value[3],$this->data[$i][$key],$key); |
|||
}else if(isset($this->regArr['callback'])){ |
|||
$this->data[$i][$key] = call_user_func($this->regArr['callback'],$this->data[$i][$key],$key); |
|||
} |
|||
|
|||
$i++; |
|||
} |
|||
} |
|||
} |
|||
if ($this->outputEncoding) { |
|||
//编码转换 |
|||
$this->data = $this->_arrayConvertEncoding($this->data, $this->outputEncoding, $this->htmlEncoding); |
|||
} |
|||
phpQuery::$documents = array(); |
|||
} |
|||
|
|||
/** |
|||
* URL请求 |
|||
* @param $url |
|||
* @return string |
|||
*/ |
|||
private function _request($url) |
|||
{ |
|||
if(function_exists('curl_init')){ |
|||
$ch = curl_init(); |
|||
curl_setopt($ch, CURLOPT_URL, $url); |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|||
curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
|||
curl_setopt($ch, CURLOPT_REFERER, $url); |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|||
$result = curl_exec($ch); |
|||
curl_close($ch); |
|||
}elseif(version_compare(PHP_VERSION, '5.0.0')>=0){ |
|||
$opts = array( |
|||
'http' => array( |
|||
'header' => "Referer:{$url}" |
|||
) |
|||
); |
|||
$result = file_get_contents($url,false,stream_context_create($opts)); |
|||
}else{ |
|||
$result = file_get_contents($url); |
|||
} |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* 移除页面head区域代码 |
|||
* @param $html |
|||
* @return mixed |
|||
*/ |
|||
private function _removeHead($html) |
|||
{ |
|||
return preg_replace('/<head.+?>.+<\/head>/is','<head></head>',$html); |
|||
} |
|||
|
|||
/** |
|||
* 获取文件编码 |
|||
* @param $string |
|||
* @return string |
|||
*/ |
|||
private function _getEncode($string) |
|||
{ |
|||
return mb_detect_encoding($string, array('ASCII', 'GB2312', 'GBK', 'UTF-8')); |
|||
} |
|||
|
|||
/** |
|||
* 转换数组值的编码格式 |
|||
* @param array $arr |
|||
* @param string $toEncoding |
|||
* @param string $fromEncoding |
|||
* @return array |
|||
*/ |
|||
private function _arrayConvertEncoding($arr, $toEncoding, $fromEncoding) |
|||
{ |
|||
// eval('$arr = '.iconv($fromEncoding, $toEncoding.'//IGNORE', var_export($arr,TRUE)).';'); |
|||
return $arr; |
|||
} |
|||
|
|||
/** |
|||
* 简单的判断一下参数是否为一个URL链接 |
|||
* @param string $str |
|||
* @return boolean |
|||
*/ |
|||
private function _isURL($str) |
|||
{ |
|||
if (preg_match('/^http(s)?:\\/\\/.+/', $str)) { |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* 去除特定的html标签 |
|||
* @param string $html |
|||
* @param string $tags_str 多个标签名之间用空格隔开 |
|||
* @return string |
|||
*/ |
|||
private function _stripTags($html,$tags_str) |
|||
{ |
|||
$tagsArr = $this->_tag($tags_str); |
|||
$html = $this->_removeTags($html,$tagsArr[1]); |
|||
$p = array(); |
|||
foreach ($tagsArr[0] as $tag) { |
|||
$p[]="/(<(?:\/".$tag."|".$tag.")[^>]*>)/i"; |
|||
} |
|||
$html = preg_replace($p,"",trim($html)); |
|||
return $html; |
|||
} |
|||
|
|||
/** |
|||
* 保留特定的html标签 |
|||
* @param string $html |
|||
* @param string $tags_str 多个标签名之间用空格隔开 |
|||
* @return string |
|||
*/ |
|||
private function _allowTags($html,$tags_str) |
|||
{ |
|||
$tagsArr = $this->_tag($tags_str); |
|||
$html = $this->_removeTags($html,$tagsArr[1]); |
|||
$allow = ''; |
|||
foreach ($tagsArr[0] as $tag) { |
|||
$allow .= "<$tag> "; |
|||
} |
|||
return strip_tags(trim($html),$allow); |
|||
} |
|||
|
|||
private function _tag($tags_str) |
|||
{ |
|||
$tagArr = preg_split("/\s+/",$tags_str,-1,PREG_SPLIT_NO_EMPTY); |
|||
$tags = array(array(),array()); |
|||
foreach($tagArr as $tag) |
|||
{ |
|||
if(preg_match('/-(.+)/', $tag,$arr)) |
|||
{ |
|||
array_push($tags[1], $arr[1]); |
|||
}else{ |
|||
array_push($tags[0], $tag); |
|||
} |
|||
} |
|||
return $tags; |
|||
} |
|||
|
|||
/** |
|||
* 移除特定的html标签 |
|||
* @param string $html |
|||
* @param array $tags 标签数组 |
|||
* @return string |
|||
*/ |
|||
private function _removeTags($html,$tags) |
|||
{ |
|||
$tag_str = ''; |
|||
if(count($tags)) |
|||
{ |
|||
foreach ($tags as $tag) { |
|||
$tag_str .= $tag_str?','.$tag:$tag; |
|||
} |
|||
phpQuery::$defaultCharset = $this->inputEncoding?$this->inputEncoding:$this->htmlEncoding; |
|||
$doc = phpQuery::newDocumentHTML($html); |
|||
pq($doc)->find($tag_str)->remove(); |
|||
$html = pq($doc)->htmlOuter(); |
|||
$doc->unloadDocument(); |
|||
} |
|||
return $html; |
|||
} |
|||
} |
|||
|
|||
/* |
|||
class Autoload |
|||
{ |
|||
public static function load($className) |
|||
{ |
|||
$files = array( |
|||
sprintf('%s/extensions/%s.php',__DIR__,$className), |
|||
sprintf('%s/extensions/vendors/%s.php',__DIR__,$className) |
|||
); |
|||
foreach ($files as $file) { |
|||
if(is_file($file)){ |
|||
require $file; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
spl_autoload_register(array('Autoload','load')); |
|||
|
|||
*/ |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,527 @@ |
|||
<?php |
|||
|
|||
/** |
|||
* 验证支付宝公钥证书是否可信 |
|||
* @param $alipayCert 支付宝公钥证书 |
|||
* @param $rootCert 支付宝根证书 |
|||
*/ |
|||
function isTrusted($alipayCert, $rootCert) |
|||
{ |
|||
$alipayCerts = readPemCertChain($alipayCert); |
|||
$rootCerts = readPemCertChain($rootCert); |
|||
if (verifyCertChain($alipayCerts, $rootCerts)) { |
|||
return verifySignature($alipayCert, $rootCert); |
|||
} else { |
|||
return false; |
|||
} |
|||
|
|||
} |
|||
|
|||
function verifySignature($alipayCert, $rootCert) |
|||
{ |
|||
$alipayCertArray = explode("-----END CERTIFICATE-----", $alipayCert); |
|||
$rootCertArray = explode("-----END CERTIFICATE-----", $rootCert); |
|||
$length = count($rootCertArray) - 1; |
|||
$checkSign = isCertSigner($alipayCertArray[0] . "-----END CERTIFICATE-----", $alipayCertArray[1] . "-----END CERTIFICATE-----"); |
|||
if (!$checkSign) { |
|||
$checkSign = isCertSigner($alipayCertArray[1] . "-----END CERTIFICATE-----", $alipayCertArray[0] . "-----END CERTIFICATE-----"); |
|||
if ($checkSign) { |
|||
$issuer = openssl_x509_parse($alipayCertArray[0] . "-----END CERTIFICATE-----")['issuer']; |
|||
for ($i = 0; $i < $length; $i++) { |
|||
$subject = openssl_x509_parse($rootCertArray[$i] . "-----END CERTIFICATE-----")['subject']; |
|||
if ($issuer == $subject) { |
|||
isCertSigner($alipayCertArray[0] . "-----END CERTIFICATE-----", $rootCertArray[$i] . $rootCertArray); |
|||
return $checkSign; |
|||
} |
|||
} |
|||
} else { |
|||
return $checkSign; |
|||
} |
|||
} else { |
|||
$issuer = openssl_x509_parse($alipayCertArray[1] . "-----END CERTIFICATE-----")['issuer']; |
|||
for ($i = 0; $i < $length; $i++) { |
|||
$subject = openssl_x509_parse($rootCertArray[$i] . "-----END CERTIFICATE-----")['subject']; |
|||
if ($issuer == $subject) { |
|||
$checkSign = isCertSigner($alipayCertArray[1] . "-----END CERTIFICATE-----", $rootCertArray[$i] . "-----END CERTIFICATE-----"); |
|||
return $checkSign; |
|||
} |
|||
} |
|||
return $checkSign; |
|||
} |
|||
} |
|||
|
|||
function readPemCertChain($cert) |
|||
{ |
|||
$array = explode("-----END CERTIFICATE-----", $cert); |
|||
$certs[] = null; |
|||
for ($i = 0; $i < count($array) - 1; $i++) { |
|||
$certs[$i] = openssl_x509_parse($array[$i] . "-----END CERTIFICATE-----"); |
|||
} |
|||
return $certs; |
|||
} |
|||
|
|||
function verifyCert($prev, $rootCerts) |
|||
{ |
|||
$nowTime = time(); |
|||
if ($nowTime < $prev['validFrom_time_t']) { |
|||
echo "证书未激活"; |
|||
return false; |
|||
} |
|||
if ($nowTime > $prev['validTo_time_t']) { |
|||
echo "证书已经过期"; |
|||
return false; |
|||
} |
|||
$subjectMap = null; |
|||
for ($i = 0; $i < count($rootCerts); $i++) { |
|||
$subjectDN = array2string($rootCerts[$i]['subject']); |
|||
$subjectMap[$subjectDN] = $rootCerts[$i]; |
|||
} |
|||
$issuerDN = array2string(($prev['issuer'])); |
|||
if (!array_key_exists($issuerDN, $subjectMap)) { |
|||
echo "证书链验证失败"; |
|||
return false; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 验证证书链是否是信任证书库中证书签发的 |
|||
* @param $alipayCerts 目标验证证书列表 |
|||
* @param $rootCerts 可信根证书列表 |
|||
*/ |
|||
function verifyCertChain($alipayCerts, $rootCerts) |
|||
{ |
|||
$sorted = sortByDn($alipayCerts); |
|||
if (!$sorted) { |
|||
echo "证书链验证失败:不是完整的证书链"; |
|||
return false; |
|||
} |
|||
//先验证第一个证书是不是信任库中证书签发的 |
|||
$prev = $alipayCerts[0]; |
|||
$firstOK = verifyCert($prev, $rootCerts); |
|||
$length = count($alipayCerts); |
|||
if (!$firstOK || $length == 1) { |
|||
return $firstOK; |
|||
} |
|||
|
|||
$nowTime = time(); |
|||
//验证证书链 |
|||
for ($i = 1; $i < $length; $i++) { |
|||
$cert = $alipayCerts[$i]; |
|||
if ($nowTime < $cert['validFrom_time_t']) { |
|||
echo "证书未激活"; |
|||
return false; |
|||
} |
|||
if ($nowTime > $cert['validTo_time_t']) { |
|||
echo "证书已经过期"; |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 将证书链按照完整的签发顺序进行排序,排序后证书链为:[issuerA, subjectA]-[issuerA, subjectB]-[issuerB, subjectC]-[issuerC, subjectD]... |
|||
* @param $certs 证书链 |
|||
*/ |
|||
function sortByDn(&$certs) |
|||
{ |
|||
//是否包含自签名证书 |
|||
$hasSelfSignedCert = false; |
|||
$subjectMap = null; |
|||
$issuerMap = null; |
|||
for ($i = 0; $i < count($certs); $i++) { |
|||
if (isSelfSigned($certs[$i])) { |
|||
if ($hasSelfSignedCert) { |
|||
return false; |
|||
} |
|||
$hasSelfSignedCert = true; |
|||
} |
|||
$subjectDN = array2string($certs[$i]['subject']); |
|||
$issuerDN = array2string(($certs[$i]['issuer'])); |
|||
$subjectMap[$subjectDN] = $certs[$i]; |
|||
$issuerMap[$issuerDN] = $certs[$i]; |
|||
} |
|||
$certChain = null; |
|||
addressingUp($subjectMap, $certChain, $certs[0]); |
|||
addressingDown($issuerMap, $certChain, $certs[0]); |
|||
|
|||
//说明证书链不完整 |
|||
if (count($certs) != count($certChain)) { |
|||
return false; |
|||
} |
|||
//将证书链复制到原先的数据 |
|||
for ($i = 0; $i < count($certs); $i++) { |
|||
$certs[$i] = $certChain[count($certs) - $i - 1]; |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* 验证证书是否是自签发的 |
|||
* @param $cert 目标证书 |
|||
*/ |
|||
function isSelfSigned($cert) |
|||
{ |
|||
$subjectDN = array2string($cert['subject']); |
|||
$issuerDN = array2string($cert['issuer']); |
|||
return ($subjectDN == $issuerDN); |
|||
} |
|||
|
|||
|
|||
function array2string($array) |
|||
{ |
|||
$string = []; |
|||
if ($array && is_array($array)) { |
|||
foreach ($array as $key => $value) { |
|||
$string[] = $key . '=' . $value; |
|||
} |
|||
} |
|||
return implode(',', $string); |
|||
} |
|||
|
|||
/** |
|||
* 向上构造证书链 |
|||
* @param $subjectMap 主题和证书的映射 |
|||
* @param $certChain 证书链 |
|||
* @param $current 当前需要插入证书链的证书,include |
|||
*/ |
|||
function addressingUp($subjectMap, &$certChain, $current) |
|||
{ |
|||
$certChain[] = $current; |
|||
if (isSelfSigned($current)) { |
|||
return; |
|||
} |
|||
$issuerDN = array2string($current['issuer']); |
|||
|
|||
if (!array_key_exists($issuerDN, $subjectMap)) { |
|||
return; |
|||
} |
|||
addressingUp($subjectMap, $certChain, $subjectMap[$issuerDN]); |
|||
} |
|||
|
|||
/** |
|||
* 向下构造证书链 |
|||
* @param $issuerMap 签发者和证书的映射 |
|||
* @param $certChain 证书链 |
|||
* @param $current 当前需要插入证书链的证书,exclude |
|||
*/ |
|||
function addressingDown($issuerMap, &$certChain, $current) |
|||
{ |
|||
$subjectDN = array2string($current['subject']); |
|||
if (!array_key_exists($subjectDN, $issuerMap)) { |
|||
return $certChain; |
|||
} |
|||
$certChain[] = $issuerMap[$subjectDN]; |
|||
addressingDown($issuerMap, $certChain, $issuerMap[$subjectDN]); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Extract signature from der encoded cert. |
|||
* Expects x509 der encoded certificate consisting of a section container |
|||
* containing 2 sections and a bitstream. The bitstream contains the |
|||
* original encrypted signature, encrypted by the public key of the issuing |
|||
* signer. |
|||
* @param string $der |
|||
* @return string on success |
|||
* @return bool false on failures |
|||
*/ |
|||
function extractSignature($der = false) |
|||
{ |
|||
if (strlen($der) < 5) { |
|||
return false; |
|||
} |
|||
// skip container sequence |
|||
$der = substr($der, 4); |
|||
// now burn through two sequences and the return the final bitstream |
|||
while (strlen($der) > 1) { |
|||
$class = ord($der[0]); |
|||
$classHex = dechex($class); |
|||
switch ($class) { |
|||
// BITSTREAM |
|||
case 0x03: |
|||
$len = ord($der[1]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$i + 2]); |
|||
} |
|||
} |
|||
return substr($der, 3 + $bytes, $len); |
|||
break; |
|||
// SEQUENCE |
|||
case 0x30: |
|||
$len = ord($der[1]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$i + 2]); |
|||
} |
|||
} |
|||
$contents = substr($der, 2 + $bytes, $len); |
|||
$der = substr($der, 2 + $bytes + $len); |
|||
break; |
|||
default: |
|||
return false; |
|||
break; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
/** |
|||
* Get signature algorithm oid from der encoded signature data. |
|||
* Expects decrypted signature data from a certificate in der format. |
|||
* This ASN1 data should contain the following structure: |
|||
* SEQUENCE |
|||
* SEQUENCE |
|||
* OID (signature algorithm) |
|||
* NULL |
|||
* OCTET STRING (signature hash) |
|||
* @return bool false on failures |
|||
* @return string oid |
|||
*/ |
|||
function getSignatureAlgorithmOid($der = null) |
|||
{ |
|||
// Validate this is the der we need... |
|||
if (!is_string($der) or strlen($der) < 5) { |
|||
return false; |
|||
} |
|||
$bit_seq1 = 0; |
|||
$bit_seq2 = 2; |
|||
$bit_oid = 4; |
|||
if (ord($der[$bit_seq1]) !== 0x30) { |
|||
die('Invalid DER passed to getSignatureAlgorithmOid()'); |
|||
} |
|||
if (ord($der[$bit_seq2]) !== 0x30) { |
|||
die('Invalid DER passed to getSignatureAlgorithmOid()'); |
|||
} |
|||
if (ord($der[$bit_oid]) !== 0x06) { |
|||
die('Invalid DER passed to getSignatureAlgorithmOid'); |
|||
} |
|||
// strip out what we don't need and get the oid |
|||
$der = substr($der, $bit_oid); |
|||
// Get the oid |
|||
$len = ord($der[1]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$i + 2]); |
|||
} |
|||
} |
|||
$oid_data = substr($der, 2 + $bytes, $len); |
|||
// Unpack the OID |
|||
$oid = floor(ord($oid_data[0]) / 40); |
|||
$oid .= '.' . ord($oid_data[0]) % 40; |
|||
$value = 0; |
|||
$i = 1; |
|||
while ($i < strlen($oid_data)) { |
|||
$value = $value << 7; |
|||
$value = $value | (ord($oid_data[$i]) & 0x7f); |
|||
if (!(ord($oid_data[$i]) & 0x80)) { |
|||
$oid .= '.' . $value; |
|||
$value = 0; |
|||
} |
|||
$i++; |
|||
} |
|||
return $oid; |
|||
} |
|||
|
|||
/** |
|||
* Get signature hash from der encoded signature data. |
|||
* Expects decrypted signature data from a certificate in der format. |
|||
* This ASN1 data should contain the following structure: |
|||
* SEQUENCE |
|||
* SEQUENCE |
|||
* OID (signature algorithm) |
|||
* NULL |
|||
* OCTET STRING (signature hash) |
|||
* @return bool false on failures |
|||
* @return string hash |
|||
*/ |
|||
function getSignatureHash($der = null) |
|||
{ |
|||
// Validate this is the der we need... |
|||
if (!is_string($der) or strlen($der) < 5) { |
|||
return false; |
|||
} |
|||
if (ord($der[0]) !== 0x30) { |
|||
die('Invalid DER passed to getSignatureHash()'); |
|||
} |
|||
// strip out the container sequence |
|||
$der = substr($der, 2); |
|||
if (ord($der[0]) !== 0x30) { |
|||
die('Invalid DER passed to getSignatureHash()'); |
|||
} |
|||
// Get the length of the first sequence so we can strip it out. |
|||
$len = ord($der[1]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$i + 2]); |
|||
} |
|||
} |
|||
$der = substr($der, 2 + $bytes + $len); |
|||
// Now we should have an octet string |
|||
if (ord($der[0]) !== 0x04) { |
|||
die('Invalid DER passed to getSignatureHash()'); |
|||
} |
|||
$len = ord($der[1]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$i + 2]); |
|||
} |
|||
} |
|||
return bin2hex(substr($der, 2 + $bytes, $len)); |
|||
} |
|||
|
|||
/** |
|||
* Determine if one cert was used to sign another |
|||
* Note that more than one CA cert can give a positive result, some certs |
|||
* re-issue signing certs after having only changed the expiration dates. |
|||
* @param string $cert - PEM encoded cert |
|||
* @param string $caCert - PEM encoded cert that possibly signed $cert |
|||
* @return bool |
|||
*/ |
|||
function isCertSigner($certPem = null, $caCertPem = null) |
|||
{ |
|||
if (!function_exists('openssl_pkey_get_public')) { |
|||
die('Need the openssl_pkey_get_public() function.'); |
|||
} |
|||
if (!function_exists('openssl_public_decrypt')) { |
|||
die('Need the openssl_public_decrypt() function.'); |
|||
} |
|||
if (!function_exists('hash')) { |
|||
die('Need the php hash() function.'); |
|||
} |
|||
if (empty($certPem) or empty($caCertPem)) { |
|||
return false; |
|||
} |
|||
// Convert the cert to der for feeding to extractSignature. |
|||
$certDer = pemToDer($certPem); |
|||
if (!is_string($certDer)) { |
|||
die('invalid certPem'); |
|||
} |
|||
// Grab the encrypted signature from the der encoded cert. |
|||
$encryptedSig = extractSignature($certDer); |
|||
if (!is_string($encryptedSig)) { |
|||
die('Failed to extract encrypted signature from certPem.'); |
|||
} |
|||
// Extract the public key from the ca cert, which is what has |
|||
// been used to encrypt the signature in the cert. |
|||
$pubKey = openssl_pkey_get_public($caCertPem); |
|||
if ($pubKey === false) { |
|||
die('Failed to extract the public key from the ca cert.'); |
|||
} |
|||
// Attempt to decrypt the encrypted signature using the CA's public |
|||
// key, returning the decrypted signature in $decryptedSig. If |
|||
// it can't be decrypted, this ca was not used to sign it for sure... |
|||
$rc = openssl_public_decrypt($encryptedSig, $decryptedSig, $pubKey); |
|||
if ($rc === false) { |
|||
return false; |
|||
} |
|||
// We now have the decrypted signature, which is der encoded |
|||
// asn1 data containing the signature algorithm and signature hash. |
|||
// Now we need what was originally hashed by the issuer, which is |
|||
// the original DER encoded certificate without the issuer and |
|||
// signature information. |
|||
$origCert = stripSignerAsn($certDer); |
|||
if ($origCert === false) { |
|||
die('Failed to extract unsigned cert.'); |
|||
} |
|||
// Get the oid of the signature hash algorithm, which is required |
|||
// to generate our own hash of the original cert. This hash is |
|||
// what will be compared to the issuers hash. |
|||
$oid = getSignatureAlgorithmOid($decryptedSig); |
|||
if ($oid === false) { |
|||
die('Failed to determine the signature algorithm.'); |
|||
} |
|||
switch ($oid) { |
|||
case '1.2.840.113549.2.2': |
|||
$algo = 'md2'; |
|||
break; |
|||
case '1.2.840.113549.2.4': |
|||
$algo = 'md4'; |
|||
break; |
|||
case '1.2.840.113549.2.5': |
|||
$algo = 'md5'; |
|||
break; |
|||
case '1.3.14.3.2.18': |
|||
$algo = 'sha'; |
|||
break; |
|||
case '1.3.14.3.2.26': |
|||
$algo = 'sha1'; |
|||
break; |
|||
case '2.16.840.1.101.3.4.2.1': |
|||
$algo = 'sha256'; |
|||
break; |
|||
case '2.16.840.1.101.3.4.2.2': |
|||
$algo = 'sha384'; |
|||
break; |
|||
case '2.16.840.1.101.3.4.2.3': |
|||
$algo = 'sha512'; |
|||
break; |
|||
default: |
|||
die('Unknown signature hash algorithm oid: ' . $oid); |
|||
break; |
|||
} |
|||
// Get the issuer generated hash from the decrypted signature. |
|||
$decryptedHash = getSignatureHash($decryptedSig); |
|||
// Ok, hash the original unsigned cert with the same algorithm |
|||
// and if it matches $decryptedHash we have a winner. |
|||
$certHash = hash($algo, $origCert); |
|||
return ($decryptedHash === $certHash); |
|||
} |
|||
|
|||
/** |
|||
* Convert pem encoded certificate to DER encoding |
|||
* @return string $derEncoded on success |
|||
* @return bool false on failures |
|||
*/ |
|||
function pemToDer($pem = null) |
|||
{ |
|||
if (!is_string($pem)) { |
|||
return false; |
|||
} |
|||
$cert_split = preg_split('/(-----((BEGIN)|(END)) CERTIFICATE-----)/', $pem); |
|||
if (!isset($cert_split[1])) { |
|||
return false; |
|||
} |
|||
return base64_decode($cert_split[1]); |
|||
} |
|||
|
|||
/** |
|||
* Obtain der cert with issuer and signature sections stripped. |
|||
* @param string $der - der encoded certificate |
|||
* @return string $der on success |
|||
* @return bool false on failures. |
|||
*/ |
|||
function stripSignerAsn($der = null) |
|||
{ |
|||
if (!is_string($der) or strlen($der) < 8) { |
|||
return false; |
|||
} |
|||
$bit = 4; |
|||
$len = ord($der[($bit + 1)]); |
|||
$bytes = 0; |
|||
if ($len & 0x80) { |
|||
$bytes = $len & 0x0f; |
|||
$len = 0; |
|||
for ($i = 0; $i < $bytes; $i++) { |
|||
$len = ($len << 8) | ord($der[$bit + $i + 2]); |
|||
} |
|||
} |
|||
return substr($der, 4, $len + 4); |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,78 @@ |
|||
<?php |
|||
/** |
|||
* 加密工具类 |
|||
* |
|||
* User: jiehua |
|||
* Date: 16/3/30 |
|||
* Time: 下午3:25 |
|||
*/ |
|||
|
|||
|
|||
/** |
|||
* 加密方法 |
|||
* @param string $str |
|||
* @return string |
|||
*/ |
|||
function encrypt($str, $screct_key) |
|||
{ |
|||
//AES, 128 模式加密数据 CBC |
|||
$screct_key = base64_decode($screct_key); |
|||
$str = trim($str); |
|||
$str = addPKCS7Padding($str); |
|||
|
|||
//设置全0的IV |
|||
|
|||
$iv = str_repeat("\0", 16); |
|||
$encrypt_str = openssl_encrypt($str, 'aes-128-cbc', $screct_key, OPENSSL_NO_PADDING, $iv); |
|||
return base64_encode($encrypt_str); |
|||
} |
|||
|
|||
/** |
|||
* 解密方法 |
|||
* @param string $str |
|||
* @return string |
|||
*/ |
|||
function decrypt($str, $screct_key) |
|||
{ |
|||
//AES, 128 模式加密数据 CBC |
|||
$str = base64_decode($str); |
|||
$screct_key = base64_decode($screct_key); |
|||
|
|||
//设置全0的IV |
|||
$iv = str_repeat("\0", 16); |
|||
$decrypt_str = openssl_decrypt($str, 'aes-128-cbc', $screct_key, OPENSSL_NO_PADDING, $iv); |
|||
$decrypt_str = stripPKSC7Padding($decrypt_str); |
|||
return $decrypt_str; |
|||
} |
|||
|
|||
/** |
|||
* 填充算法 |
|||
* @param string $source |
|||
* @return string |
|||
*/ |
|||
function addPKCS7Padding($source) |
|||
{ |
|||
$source = trim($source); |
|||
$block = 16; |
|||
|
|||
$pad = $block - (strlen($source) % $block); |
|||
if ($pad <= $block) { |
|||
$char = chr($pad); |
|||
$source .= str_repeat($char, $pad); |
|||
} |
|||
return $source; |
|||
} |
|||
|
|||
/** |
|||
* 移去填充算法 |
|||
* @param string $source |
|||
* @return string |
|||
*/ |
|||
function stripPKSC7Padding($source) |
|||
{ |
|||
$char = substr($source, -1); |
|||
$num = ord($char); |
|||
if ($num == 62) return $source; |
|||
$source = substr($source, 0, -$num); |
|||
return $source; |
|||
} |
|||
@ -0,0 +1,241 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class App { |
|||
|
|||
/** |
|||
* 根据渠道获取插件 |
|||
* @param string $type sys总后台 agent代理后台 store商家后台 |
|||
* @return array |
|||
*/ |
|||
static function get_cate_plugins($type = 'sys') { |
|||
global $_W; |
|||
if($type == 'sys'){ |
|||
$plugins = self::get_apps($_W['uniacid']); |
|||
}else if($type == 'agent'){ |
|||
$plugins = self::get_apps($_W['aid'], 'agent'); |
|||
}else if($type == 'store'){ |
|||
$plugins = self::get_apps($_W['storeid'],'store'); |
|||
} |
|||
$category = self::getCategory(); |
|||
|
|||
foreach ($plugins as $plugin) { |
|||
if ((!empty($_W['jurisdiction']) && (in_array(Util::urlRestore($plugin['cover']), $_W['jurisdiction']) || !in_array(Util::urlRestore($plugin['cover']), $_W['JUrlList']))) || empty($_W['jurisdiction'])) { |
|||
$category[$plugin['category']]['plugins'][] = $plugin; |
|||
} |
|||
} |
|||
|
|||
return $category; |
|||
} |
|||
|
|||
static function getPlugins($type = 3) { |
|||
$styles = Util::traversingFiles(PATH_PLUGIN); |
|||
$pluginsset = array(); |
|||
|
|||
foreach ($styles as $key => $value) { |
|||
if (is_store() && $value != 'rush') continue; |
|||
$config = self::ext_plugin_config($value); |
|||
if (!empty($config) && is_array($config)) { |
|||
unset($config['menus']); |
|||
//向数据库插入插件数据 |
|||
$plugininfo = pdo_get('wlmerchant_plugin', array('name' => $value)); |
|||
if (empty($plugininfo)) { |
|||
pdo_insert('wlmerchant_plugin', array('name' => $config['ident'], 'type' => $config['category'], 'title' => $config['name'], 'thumb' => '../addons/'.MODULE_NAME.'/plugin/' . $config['ident'] . '/icon.png', 'ability' => $config['des'], 'status' => 1)); |
|||
} elseif ($plugininfo['status'] != 1) { |
|||
continue; |
|||
} else { |
|||
$config['name'] = $plugininfo['title']; |
|||
$config['thumb'] = $plugininfo['thumb']; |
|||
$config['des'] = $plugininfo['ability']; |
|||
$config['displayorder'] = $plugininfo['displayorder']; |
|||
} |
|||
if ($type == 1 && $config['setting']['agent'] == 'true') { |
|||
$pluginsset[$value] = $config; |
|||
} elseif ($type == 2 && $config['setting']['system'] == 'true') { |
|||
$pluginsset[$value] = $config; |
|||
} elseif ($type == 4 && $config['setting']['store'] == 'true') { |
|||
$pluginsset[$value] = $config; |
|||
} elseif ($type == 3) { |
|||
$pluginsset[$value] = $config; |
|||
} |
|||
} |
|||
} |
|||
$pluginsset = Util::multi_array_sort($pluginsset, 'displayorder', SORT_DESC); |
|||
|
|||
return $pluginsset; |
|||
} |
|||
|
|||
static function getCategory() { |
|||
return array( |
|||
'channel' => array('name' => '渠道管理', 'color' => '#009AFE'), |
|||
'market' => array('name' => '营销应用', 'color' => '#F85959'), |
|||
'interact' => array('name' => '互动应用', 'color' => '#11CD6E'), |
|||
'expand' => array('name' => '拓展应用', 'color' => '#FEB822'), |
|||
'help' => array('name' => '辅助应用', 'color' => '#8f57ff') |
|||
); |
|||
} |
|||
|
|||
static function get_apps($id = 0, $type = 'account') { |
|||
global $_W; |
|||
if ($type == 'account') { |
|||
$plugins = self::getPlugins(2); |
|||
$perms = self::get_account_perm("plugins", $id); |
|||
}else if($type == 'store'){ |
|||
$plugins = self::getPlugins(4); |
|||
if(!empty($_W['authority'])){ |
|||
$perms = $_W['authority']; |
|||
} |
|||
if(!in_array('halfcard',$perms)){ |
|||
$plugins['halfcard']['cover'] = web_url('halfcard/halfcard_web/packagelist'); |
|||
} |
|||
if(in_array('package',$perms)){ |
|||
$perms[] = 'halfcard'; |
|||
} |
|||
} else { |
|||
$plugins = self::getPlugins(1); |
|||
$perms = self::get_account_perm("plugins"); |
|||
if (!empty($id)) { |
|||
$aperms = Area::getSingleGroup(pdo_getcolumn(PDO_NAME . 'agentusers', array('uniacid' => $_W['uniacid'], 'id' => $id), 'groupid')); |
|||
} |
|||
$perms = !empty($perms) ? (!empty($aperms['package']) ? array_intersect($perms, $aperms['package']) : $perms) : $aperms['package']; |
|||
} |
|||
|
|||
foreach ($plugins as $key => $row) { |
|||
if (!empty($perms) && !in_array($row["ident"], $perms)) { |
|||
unset($plugins[$key]); |
|||
} |
|||
} |
|||
return $plugins; |
|||
} |
|||
|
|||
static function get_account_perm($key = '', $uniacid = 0) { |
|||
global $_W; |
|||
if (empty($uniacid)) { |
|||
$uniacid = $_W['uniacid']; |
|||
} |
|||
$perm = pdo_get('wlmerchant_perm_account', array('uniacid' => $uniacid)); |
|||
if (empty($perm)) { |
|||
return false; |
|||
} |
|||
if (!empty($perm)) { |
|||
$perm['plugins'] = iunserializer($perm['plugins']); |
|||
if (!is_array($perm['plugins'])) { |
|||
$perm['plugins'] = array(); |
|||
} |
|||
if (empty($perm['plugins'])) { |
|||
$perm['plugins'] = array('none'); |
|||
} |
|||
if (!empty($key)) { |
|||
return $perm[$key]; |
|||
} |
|||
} |
|||
return $perm; |
|||
} |
|||
|
|||
static function ext_plugin_config($plugin) { |
|||
$filename = PATH_PLUGIN . $plugin . '/config.xml'; |
|||
if (!file_exists($filename)) { |
|||
return array(); |
|||
} |
|||
$manifest = self::ext_plugin_config_parse(file_get_contents($filename)); |
|||
if (empty($manifest['name']) || $manifest['ident'] != $plugin) { |
|||
return array(); |
|||
} |
|||
return $manifest; |
|||
} |
|||
|
|||
static function ext_plugin_config_parse($xml) { |
|||
if (!strexists($xml, '<manifest')) { |
|||
$xml = base64_decode($xml); |
|||
} |
|||
if (empty($xml)) { |
|||
return array(); |
|||
} |
|||
$dom = new DOMDocument(); |
|||
$dom->loadXML($xml); |
|||
$root = $dom->getElementsByTagName('manifest')->item(0); |
|||
if (empty($root)) { |
|||
return array(); |
|||
} |
|||
|
|||
$application = $root->getElementsByTagName('application')->item(0); |
|||
if (empty($application)) { |
|||
return array(); |
|||
} |
|||
$manifest = array( |
|||
'name' => trim($application->getElementsByTagName('name')->item(0)->textContent), |
|||
'ident' => trim($application->getElementsByTagName('identifie')->item(0)->textContent), |
|||
'version' => trim($application->getElementsByTagName('version')->item(0)->textContent), |
|||
'category' => trim($application->getElementsByTagName('type')->item(0)->textContent), |
|||
'des' => trim($application->getElementsByTagName('description')->item(0)->textContent), |
|||
'author' => trim($application->getElementsByTagName('author')->item(0)->textContent), |
|||
'url' => trim($application->getElementsByTagName('url')->item(0)->textContent), |
|||
); |
|||
|
|||
$manifest['setting']['store'] = 'false'; |
|||
$manifest['setting']['agent'] = 'false'; |
|||
$manifest['setting']['system'] = 'false'; |
|||
$manifest['setting']['task'] = 'false'; |
|||
$setting = $root->getElementsByTagName('setting')->item(0); |
|||
if (!empty($setting)) { |
|||
$agent = $setting->getElementsByTagName('agent')->item(0); |
|||
if (!empty($agent) && $agent->getAttribute('embed') == 'true') { |
|||
$manifest['setting']['agent'] = 'true'; |
|||
} |
|||
$system = $setting->getElementsByTagName('system')->item(0); |
|||
if (!empty($system) && $system->getAttribute('embed') == 'true') { |
|||
$manifest['setting']['system'] = 'true'; |
|||
} |
|||
$store = $setting->getElementsByTagName('store')->item(0); |
|||
if (!empty($store) && $store->getAttribute('embed') == 'true') { |
|||
$manifest['setting']['store'] = 'true'; |
|||
} |
|||
$task = $setting->getElementsByTagName('task')->item(0); |
|||
if (!empty($task) && $task->getAttribute('embed') == 'true') { |
|||
$manifest['setting']['task'] = 'true'; |
|||
} |
|||
} |
|||
if (defined('IN_STORE') && $manifest['setting']['store'] == 'true') { |
|||
$elm = $root->getElementsByTagName('storemenu')->item(0); |
|||
} else if (defined('IN_WEB') && $manifest['setting']['agent']) { |
|||
$elm = $root->getElementsByTagName('agentmenu')->item(0); |
|||
} else { |
|||
$elm = $root->getElementsByTagName('systemmenu')->item(0); |
|||
} |
|||
$manifest['menus'] = self::ext_plugin_config_entries($elm, $manifest); |
|||
|
|||
return $manifest; |
|||
} |
|||
|
|||
static function ext_plugin_config_entries($elm, &$manifest) { |
|||
$frames = array(); |
|||
$menus = $elm->getElementsByTagName('menu'); |
|||
foreach ($menus as $i => $cmenu) { |
|||
$frames[$manifest['ident'] . $i]['title'] = '<i class="fa ' . $cmenu->getAttribute('font') . '"></i> ' . $cmenu->getAttribute('title'); |
|||
$entries = $cmenu->getElementsByTagName('entry'); |
|||
for ($j = 0; $j < $entries->length; $j++) { |
|||
$entry = $entries->item($j); |
|||
$ac = $entry->getAttribute('ac'); |
|||
$do = $entry->getAttribute('do'); |
|||
$iscover = $entry->getAttribute('iscover'); |
|||
$target = $entry->getAttribute('target'); |
|||
$actions = json_decode($entry->getAttribute('actions')); |
|||
$actions = !empty($actions) ? $actions : array('ac', $ac, 'do', $do); |
|||
$row = array( |
|||
'url' => web_url($manifest['ident'] . '/' . $ac . '/' . $do), |
|||
'title' => $entry->getAttribute('title'), |
|||
'actions' => $actions, |
|||
'active' => '' |
|||
); |
|||
$manifest['target'] = $target ? : '_self'; |
|||
if ($iscover == 'true') { |
|||
$manifest['cover'] = $row['url']; |
|||
} |
|||
if (!empty($row['title']) && !empty($row['url'])) { |
|||
$frames[$manifest['ident'] . $i]['items'][$ac . $do] = $row; |
|||
} |
|||
} |
|||
} |
|||
return $frames; |
|||
} |
|||
} |
|||
@ -0,0 +1,349 @@ |
|||
<?php |
|||
|
|||
defined('IN_IA') or exit('Access Denied'); |
|||
class Category |
|||
{ |
|||
static protected $tableName = 'cultivate_class'; |
|||
/** |
|||
* 查询所有商户分类 |
|||
*/ |
|||
static function getAllCategory($page = 0 , $pagenum = 10 , $parentid = 0) |
|||
{ |
|||
global $_W; |
|||
$re['data'] = pdo_fetchall("select * from" . tablename(PDO_NAME . self::$tableName) . "where uniacid=:uniacid and aid=:aid and parentid=:parentid order by displayorder desc limit " . $page * $pagenum . "," . $pagenum , [ |
|||
':uniacid' => $_W['uniacid'] , |
|||
':aid' => $_W['aid'] , |
|||
':parentid' => $parentid |
|||
]); |
|||
$re['count'] = pdo_fetchcolumn("select count(*) from" . tablename(PDO_NAME . 'cultivate_class') . "where uniacid=:uniacid and aid=:aid and parentid=:parentid" , [ |
|||
':uniacid' => $_W['uniacid'] , |
|||
':aid' => $_W['aid'] , |
|||
':parentid' => $parentid |
|||
]); |
|||
return $re; |
|||
} |
|||
/** |
|||
* 单个商户分类查询 |
|||
*/ |
|||
static function getSingleCategory($id,$fields = "*") |
|||
{ |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
return pdo_get(PDO_NAME . self::$tableName , ['id' => $id , 'uniacid' => $_W['uniacid']], $fields); |
|||
} |
|||
|
|||
/** |
|||
* 多个商户分类查询 |
|||
* @param $id |
|||
* @param $fields |
|||
* @param $stint // 限制 限制2级不显示 推荐分类 |
|||
* @return array|false|mixed |
|||
*/ |
|||
static function getChildCategoryAll($id,$fields = "*",$stint = false) |
|||
{ |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
$where = " parentid = {$id} and uniacid = {$_W['uniacid']} and status = 1"; |
|||
if ($stint) $where .= " and name != '推荐'"; |
|||
return pdo_getall(PDO_NAME . self::$tableName , $where,$fields,'','displayorder desc,id desc'); |
|||
} |
|||
/** |
|||
* 编辑商户分类 |
|||
*/ |
|||
static function categoryEdit($arr , $id = '') |
|||
{ |
|||
global $_W; |
|||
if (empty($arr)) return false; |
|||
if (!empty($id) && $id != '') return pdo_update(PDO_NAME . self::$tableName , $arr , [ |
|||
'id' => $id , |
|||
'uniacid' => $_W['uniacid'] , |
|||
'aid' => $_W['aid'] |
|||
]); |
|||
$arr['aid'] = $_W['aid']; |
|||
$arr['uniacid'] = $_W['uniacid']; |
|||
$arr['create_time'] = time(); |
|||
return pdo_insert(PDO_NAME . self::$tableName , $arr); |
|||
} |
|||
/** |
|||
* 递归删除商户分类 |
|||
*/ |
|||
static function categoryDelete($id) |
|||
{ |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
$arr = pdo_getall(PDO_NAME . self::$tableName , ['uniacid' => $_W['uniacid'] , 'parentid' => $id]); |
|||
if (empty($arr)) return pdo_delete(PDO_NAME . self::$tableName , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
foreach ($arr as $key => $value) { |
|||
if (!self::categoryDelete($value['id'])) return false; |
|||
} |
|||
return pdo_delete(PDO_NAME . self::$tableName , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
} |
|||
|
|||
/** |
|||
* 获取分类为树形结构 |
|||
* @param $parentid // 父id |
|||
* @param $filed // 字段 |
|||
* @param $type // 分类类型 |
|||
* @param $stint // 限制 限制2级不显示 推荐分类 |
|||
* @return array |
|||
*/ |
|||
static function getTreeCategory($parentid = 0,$filed = "*",$type='',$stint = true) |
|||
{ |
|||
global $_W; |
|||
$where = 'uniacid=:uniacid and aid=:aid and parentid=:parentid and status = 1'; |
|||
if (is_numeric($type)) $where .= " and type = {$type}"; |
|||
$list = pdo_fetchall("select {$filed} from" . tablename(PDO_NAME . self::$tableName) . "where {$where} order by displayorder desc ", [ |
|||
':uniacid' => $_W['uniacid'] , |
|||
':aid' => $_W['aid'] , |
|||
':parentid' => $parentid |
|||
]); |
|||
$result = []; |
|||
foreach ($list as $category) { |
|||
|
|||
$where2 = 'where uniacid=:uniacid and aid=:aid and parentid=:parentid and status = 1'; |
|||
if ($stint) $where2 .= " and name != '推荐'"; |
|||
$list2 = pdo_fetchall("select {$filed} from" . tablename(PDO_NAME . self::$tableName) . "{$where2} order by displayorder desc ", [ |
|||
':uniacid' => $_W['uniacid'] , |
|||
':aid' => $_W['aid'] , |
|||
':parentid' => $category['id'] |
|||
]); |
|||
if ($list2) { |
|||
$category['children'] = $list2; |
|||
} |
|||
$result[] = $category; |
|||
} |
|||
return $result; |
|||
} |
|||
|
|||
/** |
|||
* 获取招聘子集分类 |
|||
* @param $job_type // 工作类型 --- replace |
|||
* @return array|false|mixed |
|||
*/ |
|||
static function getCategoryRecruit($job_type = 1) |
|||
{ |
|||
$id = ''; |
|||
if ($job_type == 1) { |
|||
$id = '9'; |
|||
} elseif ($job_type == 2 || $job_type == 3) { |
|||
$id = '7'; |
|||
}/* elseif ($job_type == 3) { |
|||
$id = '8'; 8 修改为企业专区 |
|||
}*/ |
|||
return pdo_getall(PDO_NAME . self::$tableName, ['parentid' => $id, 'status' => 1],['id','name'],'','displayorder desc'); |
|||
} |
|||
|
|||
/** |
|||
* 获取商品指定分类 |
|||
* @return array|false|mixed --- replace |
|||
*/ |
|||
static function getStoreCategory() |
|||
{ |
|||
//$idArr = [1,2,3,4]; // |
|||
return pdo_getall(PDO_NAME . 'cultivate_class',['status' => 1,'parentid' => 0,'type' => 1],['id','name']); |
|||
} |
|||
|
|||
/** |
|||
* 获取分类所有视频 |
|||
* @param $category_id // 分类ID |
|||
* @param $fields // 查询字段 |
|||
* @param $is_status // 是否查询状态 为显示的数据 |
|||
* @param $mid // 用户id |
|||
* @return array|false|mixed |
|||
*/ |
|||
static function categoryVideoAll($category_id,$fields = '*',$is_status = false,$mid = '',$pindex = 0, $psize = 10) |
|||
{ |
|||
if (empty($category_id)) return false; |
|||
$where = ['cc_id' => $category_id]; |
|||
if ($is_status) $where['status'] = 1; |
|||
$pager = ''; |
|||
$total = 0; |
|||
if ($pindex) { |
|||
$memberData = Util::getNumData($fields, PDO_NAME . 'cultivate_class_video', $where, 'sort DESC', $pindex, $psize, 1); |
|||
$list = $memberData[0]; |
|||
$pager = $memberData[1]; |
|||
$total = $memberData[2]; |
|||
} else { |
|||
$list = pdo_getall(PDO_NAME . 'cultivate_class_video',$where,$fields,'','sort DESC'); |
|||
} |
|||
|
|||
foreach ($list as &$value) { |
|||
$value['video_link'] = tomedia($value['video_link']); |
|||
if ($value['video_cover']) $value['video_cover'] = tomedia($value['video_cover']); |
|||
if ($value['create_time']) $value['create_time'] = date("Y-m-d H:i:s",$value['create_time']); |
|||
// 获取点赞数量 |
|||
$likeids = unserialize($value['likeids']); |
|||
if (!empty($likeids) && is_array($likeids)) { |
|||
// 判断当前用户是否已经点赞 |
|||
if (!empty($mid)) { |
|||
$value['is_like'] = false; |
|||
if (in_array($mid,$likeids)) $value['is_like'] = true; |
|||
} |
|||
} |
|||
# 删除不必要字段 |
|||
unset($value['likeids']); |
|||
} |
|||
return [ |
|||
'list' => $list, |
|||
'pager' => $pager, |
|||
'total' => $total |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* 获取分类所有视频 |
|||
* @param $id // 视频ID |
|||
* @return false|mixed |
|||
*/ |
|||
static function categoryVideoFind($id) |
|||
{ |
|||
if (empty($id)) return false; |
|||
return pdo_get(PDO_NAME . 'cultivate_class_video',['id' => $id],'*'); |
|||
} |
|||
|
|||
/** |
|||
* 获取商户关联分类 |
|||
* @param int $storeid // 商户id |
|||
* @param int $parentid // 父级id |
|||
* @return array|false|mixed |
|||
*/ |
|||
static function getStoreCategoryAll(int $storeid,int $parentid = 0) { |
|||
$sql = "select b.id,b.id as cc_id,b.name from ims_wlmerchant_merchant_class as a join ims_wlmerchant_cultivate_class as b" |
|||
." on a.cc_id = b.id where a.storeid = {$storeid} and b.type = 1 and b.status = 1 and b.parentid = {$parentid}"; |
|||
return pdo_fetchall($sql) ?: []; |
|||
} |
|||
|
|||
/** |
|||
* 判断用户是否有 分类权限 |
|||
* @param $storeid // 商户id |
|||
* @param $is_parent // 是否有父级 |
|||
* @return array|int[] |
|||
*/ |
|||
static function judgeStoreClassRights($storeid,$is_parent = false) |
|||
{ |
|||
$sql = "select b.id,b.id as cc_id,b.name from ims_wlmerchant_merchant_class as a join ims_wlmerchant_cultivate_class as b" |
|||
." on a.cc_id = b.id where a.storeid = {$storeid} and b.type = 1 and b.status = 1"; |
|||
$sql .= $is_parent ? " and b.parentid != 0" : " and b.parentid = 0"; |
|||
$list = pdo_fetchall($sql) ?: []; |
|||
if (empty($list)) { |
|||
return ['status' => 0, 'msg' => '没有权限,请联系客服申请添加分类']; |
|||
} |
|||
return ['status' => 1]; |
|||
} |
|||
|
|||
/** |
|||
* 同步子级分类类型 |
|||
* @param $categoryid |
|||
* @param $data |
|||
* @return void |
|||
*/ |
|||
static function syncCategroyType($categoryid,$data = []){ |
|||
if (empty($data)) $data = pdo_get(PDO_NAME . self::$tableName,['id' => $categoryid]); |
|||
if (is_numeric($data['type'])) { |
|||
pdo_update(PDO_NAME . self::$tableName,['type' => $data['type']],['parentid' => $categoryid]); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取视频评论 |
|||
* @param $commentWhere |
|||
* @param $mid |
|||
* @param $pindex |
|||
* @param $psize |
|||
* @param $fieldsType |
|||
* @param $orderby |
|||
* @return array |
|||
*/ |
|||
public static function getVideoComment($commentWhere,$mid = '',$pindex = 1,$psize = 10,$fieldsType=1,$orderby=' likenum desc,createtime desc') |
|||
{ |
|||
$fields = $fieldsType ? "id,content,createtime,pid,oneid,likenum,likeids,mid" : "*"; |
|||
|
|||
$memberData = Util::getNumData($fields, PDO_NAME . 'cultivate_class_comment', $commentWhere, $orderby, $pindex, $psize, 1); |
|||
$comment = $memberData[0]; |
|||
$pager = $memberData[1]; |
|||
$total = $memberData[2]; |
|||
foreach ($comment as &$commentVal) { |
|||
# 评论时间 |
|||
$commentVal['createtime'] = date("Y-m-d H:i:s",$commentVal['createtime']); |
|||
# 评论解密(为了可以发表情) |
|||
$commentVal['content'] = is_base64($commentVal['content']) ? base64_decode($commentVal['content']) : $commentVal['content']; |
|||
# 判断是否当前用户是否点赞 |
|||
$commentLikeids = unserialize($commentVal['likeids']); |
|||
if (!empty($commentLikeids) && is_array($commentLikeids)) { |
|||
if (!empty($mid)) { |
|||
$commentVal['is_like'] = false; |
|||
if (in_array($mid,$commentLikeids)) $commentVal['is_like'] = true; |
|||
} |
|||
} |
|||
# 是否显示查看回复 |
|||
$commentVal['is_query'] = false; |
|||
$commentVal['reply_count'] = 0; |
|||
if (!$commentVal['oneid']) { |
|||
$count = pdo_count(PDO_NAME . 'cultivate_class_comment',['oneid' => $commentVal['id'],'status' => 1]); |
|||
if ($count > 0) $commentVal['is_query'] = true; |
|||
$commentVal['reply_count'] = $count; |
|||
} |
|||
# 用户名名称及头像 |
|||
Member::getMemberInfo($commentVal,$commentVal['mid']); |
|||
if (!empty($commentVal['pid'])) { |
|||
$pComment = pdo_get(PDO_NAME . 'cultivate_class_comment',['id' => $commentVal['pid']],['mid']); |
|||
$quiltArr = []; |
|||
Member::getMemberInfo($quiltArr,$pComment['mid']); |
|||
$commentVal['quilt_nickname'] = $quiltArr['nickname']; |
|||
$commentVal['quilt_avatar'] = $quiltArr['avatar']; |
|||
$commentVal['quilt_mid'] = $pComment['mid']; |
|||
} |
|||
# 删除多余字段 |
|||
unset($commentVal['likeids']); |
|||
} |
|||
return [ |
|||
'pager' => $pager, |
|||
'list' => $comment, |
|||
'total' => $total, |
|||
]; |
|||
} |
|||
|
|||
/** |
|||
* Comment: 发送回复信息模板消息通知 |
|||
* Author: zzw |
|||
* Date: 2020/3/16 14:41 |
|||
* @param int $video_id 视频id |
|||
* @param int $cid 回复信息id |
|||
* @param int $smid 回复人id(发布回复信息的用户的id) |
|||
* @param int $amid 被回复人id(接收回复信息的用户的id) |
|||
* @param int $source 渠道信息 |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public static function setReplyModelInfo($video_id,$cid,$smid,$amid,$source = 1){ |
|||
#1、基本信息获取 |
|||
$nickname = pdo_getcolumn(PDO_NAME."member",['id'=>$smid],'nickname');//获取回复人昵称 |
|||
$time = pdo_getcolumn(PDO_NAME."cultivate_class_comment",['id'=>$cid],'createtime');//回复时间 |
|||
#2、发送模板消息通知用户 |
|||
$modelData = [ |
|||
'first' => '您的评论被回复了' , |
|||
'type' => '评论回复提醒' ,//业务类型 |
|||
'content' => '用户['.$nickname.']对您的评论进行了回复!' ,//业务内容 |
|||
'status' => '待回复' ,//处理结果 |
|||
'time' => date("Y-m-d H:i:s",$time) ,//操作时间 |
|||
'remark' => '' |
|||
]; |
|||
$link = h5_url('pages/subPages/postDetails/postDetails',['id'=>$video_id]);# 注意确认是否为小程序路径 |
|||
TempModel::sendInit('service',$amid,$modelData,$source,$link); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 递归删除视频评论 |
|||
*/ |
|||
static function videoCommentDelete($id) |
|||
{ |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
$arr = pdo_getall(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'pid' => $id]); |
|||
if (empty($arr)) return pdo_delete(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
foreach ($arr as $key => $value) { |
|||
if (!self::videoCommentDelete($value['id'])) return false; |
|||
} |
|||
return pdo_delete(PDO_NAME . 'cultivate_class_comment' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
} |
|||
} |
|||
@ -0,0 +1,177 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Cloud { |
|||
|
|||
//获取授权信息 |
|||
static function auth_info() { |
|||
global $_W; |
|||
//获取授权信息 |
|||
$authinfo = self::wl_syssetting_read('authinfo'); |
|||
$auth = self::api_post(['url' => $_W['siteroot'], 'code' => $authinfo['code'] ? $authinfo['code'] : '']); |
|||
//写入授权信息 |
|||
if ($auth['code'] == 0 && !empty($auth['data'])) { |
|||
self::wl_syssetting_save($auth['data'], 'authinfo'); |
|||
return $auth['data']; |
|||
} |
|||
return error(1, $auth['message']); |
|||
} |
|||
|
|||
static function auth_db_update() { |
|||
$dbfile = PATH_CORE . "common/dbfile.php"; |
|||
if (!file_exists($dbfile)) { |
|||
return error(1, 'dbfile文件不存在,请检查后再试'); |
|||
} |
|||
|
|||
$diff_sqls = []; |
|||
$tables = json_decode(base64_decode(file_get_contents($dbfile)), true); |
|||
foreach ($tables as $table) { |
|||
if (!strexists($table['table'], 'wlmerchant') && IMS_FAMILY != 'wl') { |
|||
continue; |
|||
} |
|||
$diff_sqls = array_merge($diff_sqls, WeliamDb::table_upgrade($table)); |
|||
} |
|||
|
|||
return $diff_sqls; |
|||
} |
|||
|
|||
static function auth_up_data() { |
|||
//数据库更新 |
|||
$sqls = Cloud::auth_db_update(); |
|||
|
|||
//商家分类更新 |
|||
$cate_count = pdo_getcolumn('wlmerchant_merchant_cate', [], 'COUNT(sid)'); |
|||
if (empty($cate_count)) { |
|||
$stores = pdo_getall('wlmerchant_merchantdata', array(), array('id')); |
|||
foreach ($stores as $store) { |
|||
$sqls[] = ['type' => 'store_cate', 'sid' => $store['id']]; |
|||
} |
|||
} |
|||
|
|||
return $sqls; |
|||
} |
|||
|
|||
static function data_store_cate($sid) { |
|||
$store = pdo_get('wlmerchant_merchantdata', array('id' => $sid), array('onelevel', 'twolevel')); |
|||
if (!empty($store)) { |
|||
$data = array('sid' => $sid, 'onelevel' => $store['onelevel'], 'twolevel' => $store['twolevel']); |
|||
$cate = pdo_get('wlmerchant_merchant_cate', $data); |
|||
if (empty($cate)) { |
|||
pdo_insert('wlmerchant_merchant_cate', $data); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 系统设置保存 |
|||
* @param $data 值 |
|||
* @param $key 键 |
|||
* @return bool |
|||
*/ |
|||
static function wl_syssetting_save($data, $key) { |
|||
if (empty($key)) { |
|||
return FALSE; |
|||
} |
|||
$record = array(); |
|||
$record['value'] = iserializer($data); |
|||
if ($key == 'taskcover') { |
|||
$record['v4flag'] = 1; |
|||
$exists = pdo_getcolumn(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => -1, 'v4flag' => 1), 'id'); |
|||
} else { |
|||
$exists = pdo_getcolumn(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => -1), 'id'); |
|||
} |
|||
if ($exists) { |
|||
$return = pdo_update(PDO_NAME . 'setting', $record, array('id' => $exists)); |
|||
} else { |
|||
$record['key'] = $key; |
|||
$record['uniacid'] = -1; |
|||
$return = pdo_insert(PDO_NAME . 'setting', $record); |
|||
} |
|||
Cache::deleteCache('syssetting', $key); |
|||
return $return; |
|||
} |
|||
|
|||
/** |
|||
* 系统设置读取 |
|||
* @param $key |
|||
* @return array|string |
|||
*/ |
|||
static function wl_syssetting_read($key) { |
|||
$settings = Cache::getCache('syssetting', $key); |
|||
if (empty($settings)) { |
|||
if ($key == 'taskcover') { |
|||
$settings = pdo_get(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => -1, 'v4flag' => 1), array('value')); |
|||
} else { |
|||
$settings = pdo_get(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => -1), array('value')); |
|||
} |
|||
if (is_array($settings)) { |
|||
$settings = iunserializer($settings['value']); |
|||
} else { |
|||
$settings = ''; |
|||
} |
|||
Cache::setCache('syssetting', $key, $settings); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
static function files_exit() { |
|||
$file = PATH_MODULE . 'temp/upgrade_file.txt'; |
|||
if (!file_exists($file)) { |
|||
return FALSE; |
|||
} |
|||
$upgrade_files = json_decode(file_get_contents($file), true); |
|||
$upgrade_files = array_column($upgrade_files, 'path'); |
|||
|
|||
$local_files = FilesHandle::file_tree(substr(PATH_MODULE, 0, -1)); |
|||
foreach ($local_files as $sk => &$sf) { |
|||
if (strexists($sf, '.log') || strexists($sf, MODULE_NAME . '/data/') || strexists($sf, MODULE_NAME . '/temp/') || (strexists($sf, '/view/') && !strexists($sf, '/view/default/')) || strexists($sf, MODULE_NAME . '/icon.png') || strexists($sf, MODULE_NAME . '/icon-custom.jpg')) { |
|||
unset($local_files[$sk]); |
|||
continue; |
|||
} |
|||
$sf = str_replace(PATH_MODULE, "", $sf); |
|||
} |
|||
|
|||
$diff_files = array_diff($local_files, $upgrade_files); |
|||
foreach ($diff_files as $key => $value) { |
|||
unlink(PATH_MODULE . $value); |
|||
} |
|||
FilesHandle::file_rm_empty_dir(PATH_MODULE); |
|||
|
|||
//异常文件需要删除 |
|||
$abnormal = array(PATH_CORE . '/common/func.php', IA_ROOT . '/app/func.php', IA_ROOT . '/web/func.php'); |
|||
foreach ($abnormal as $k => $val) { |
|||
unlink($val); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 删除客户未购买的插件 |
|||
* @param $plugin |
|||
*/ |
|||
static function files_plugin_exit($plugin) { |
|||
$dirs = scandir(PATH_PLUGIN); |
|||
$delplugin = array_diff($dirs, $plugin, array('.', '..')); |
|||
|
|||
foreach ($delplugin as $key => $value) { |
|||
if (!strexists($value, '.')) { |
|||
Util::deleteAll(PATH_PLUGIN . $value, 1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static function api_post($data = array()) { |
|||
global $_W; |
|||
if (empty($data['pd'])) { |
|||
$data['pd'] = 'weliam_smartcity'; |
|||
} |
|||
if (IMS_FAMILY == 'wl') { |
|||
$data['ind'] = 'true'; |
|||
} |
|||
$resp = Util::httpPost(WELIAM_API, $data); |
|||
if (!is_error($resp)) { |
|||
$resp = @json_decode($resp, true); |
|||
} |
|||
return $resp; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,145 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Commons { |
|||
/** |
|||
* Comment: 操作成功输出方法 |
|||
* Author: zzw |
|||
* Date: 2019/7/16 9:35 |
|||
* @param string $message |
|||
* @param array $data |
|||
*/ |
|||
public function renderSuccess ($message = '操作成功' , $data = []){ |
|||
exit(json_encode(array( |
|||
'errno' => 0 , |
|||
'message' => $message , |
|||
'data' => $data, |
|||
))); |
|||
} |
|||
/** |
|||
* Comment: 操作失败返回内容 |
|||
* Author: zzw |
|||
* Date: 2019/7/16 9:36 |
|||
* @param string $message |
|||
* @param array $data |
|||
*/ |
|||
public function renderError ($message = '操作失败' , $data = []){ |
|||
exit(json_encode(array( |
|||
'errno' => 1 , |
|||
'message' => $message , |
|||
'data' => $data, |
|||
))); |
|||
} |
|||
/** |
|||
* Comment: 操作成功输出方法 |
|||
* Author: zzw |
|||
* Date: 2019/7/16 9:35 |
|||
* @param string $message |
|||
* @param array $data |
|||
*/ |
|||
public static function sRenderSuccess ($message = '操作成功' , $data = []){ |
|||
exit(json_encode(array( |
|||
'errno' => 0 , |
|||
'message' => $message , |
|||
'data' => $data, |
|||
))); |
|||
} |
|||
/** |
|||
* Comment: 操作失败返回内容 |
|||
* Author: zzw |
|||
* Date: 2019/7/16 9:36 |
|||
* @param string $message |
|||
* @param array $data |
|||
*/ |
|||
public static function sRenderError ($message = '操作失败' , $data = []){ |
|||
exit(json_encode(array( |
|||
'errno' => 1 , |
|||
'message' => $message , |
|||
'data' => $data, |
|||
))); |
|||
} |
|||
/** |
|||
* Comment: 距离转换 |
|||
* Author: zzw |
|||
* Date: 2019/12/17 11:38 |
|||
* @param int $distance 距离数值 |
|||
* @return string |
|||
*/ |
|||
public static function distanceConversion($distance){ |
|||
if($distance > 0){ |
|||
if ($distance > 9999998) { |
|||
$newDistance = " "; |
|||
} else if ($distance > 1000) { |
|||
$newDistance = (floor(($distance / 1000) * 10) / 10) . "km"; |
|||
} else { |
|||
$newDistance = round($distance) . "m"; |
|||
} |
|||
} |
|||
return !empty($newDistance) ? $newDistance : ''; |
|||
} |
|||
/** |
|||
* Comment: 获取社群信息 |
|||
* Author: zzw |
|||
* Date: 2019/12/17 17:09 |
|||
* @param int $id |
|||
* @return array |
|||
*/ |
|||
public static function getCommunity($id,$title = '入群'){ |
|||
$info = pdo_get(PDO_NAME . "community" , [ 'id' => $id] , ['id', 'communname','systel','commundesc' , 'communimg' , 'communqrcode' ]); |
|||
if($info){ |
|||
$data = [ |
|||
'title' => $title , |
|||
'community_id' => $info['id'] ? : '' , |
|||
'name' => $info['communname'] ? : '' , |
|||
'introduce' => $info['commundesc'] ? : '' , |
|||
'imgUrl' => tomedia($info['communimg']) ? : '' , |
|||
'qrcodeUrl' => tomedia($info['communqrcode']) ? : '' , |
|||
'phone' => $info['systel'] ? : '' , |
|||
'community' => '' , |
|||
]; |
|||
}else{ |
|||
$data = []; |
|||
} |
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 提现时间处理 |
|||
* Author: zzw |
|||
* Date: 2021/3/15 11:44 |
|||
* @param int|string $lastTime 时间戳 |
|||
* @param int|string $day 天数 |
|||
* @return array|int[] |
|||
*/ |
|||
public static function handleTime($lastTime,$day){ |
|||
$time = time(); |
|||
$lastTime = $lastTime + ($day * 86400);//下一次申请提现应该在本时间之后 |
|||
if ($lastTime > $time) { |
|||
$distance = $lastTime - $time; |
|||
$d = floor($distance / 86400);//天 |
|||
$h = floor($distance % 86400 / 3600);//时 |
|||
$i = floor((($distance % 86400) % 3600) / 60);//分 |
|||
$str = "提现申请频率为{$day}天/次。请于"; |
|||
$d > 0 && $str .= $d . '天'; |
|||
$h > 0 && $str .= $h . '时'; |
|||
$i > 0 && $str .= $i . '分'; |
|||
if ($d < 1) { |
|||
$s = floor(((($distance % 86400) % 3600) % 60));//分 |
|||
$s > 0 && $str .= $s . '秒'; |
|||
} |
|||
$str .= '后进行提现申请'; |
|||
|
|||
return [ |
|||
'status'=>1, |
|||
'str'=>$str |
|||
]; |
|||
} |
|||
return ['status'=>0]; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,94 @@ |
|||
<?php |
|||
/** |
|||
* Comment: 定制信息判断 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 |
|||
* Time: 16:10 |
|||
*/ |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Customized{ |
|||
/** |
|||
* Comment: 判断当前用户是否存在该定制功能的使用权 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 16:25 |
|||
* @param $name |
|||
* @return bool |
|||
*/ |
|||
public static function init($name){ |
|||
if($name == 'allocation' || $name == 'pft147'){ |
|||
return 1; |
|||
} |
|||
$authinfo = Cloud::wl_syssetting_read('authinfo'); |
|||
$list = self::authList($name); |
|||
return in_array($authinfo['code'],$list); |
|||
} |
|||
/** |
|||
* Comment: 获取授权码列表 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 16:24 |
|||
* @param $name |
|||
* @return array |
|||
*/ |
|||
protected static function authList($name){ |
|||
//定制信息授权列表 功能名称 => 【授权码数组】 |
|||
$list = [ |
|||
//打印消息授权(568定制) |
|||
'printing' => ['5AFBA464F822EAE4959837E979D30171'], |
|||
//自定义装修 用户信息组件(881定制) |
|||
'diy_userInfo' => ['996C4795D9661D590400C0B0DC93A193'], |
|||
//全民分销商|生成分销订单后解绑上下级|商户买单普通用户折扣|分销商自动提现 336定制 |
|||
'customized336' => ['69EF7FE62BAEBD7D23741FD76687EA83'], |
|||
//测试服务商分账功能 |
|||
'allocation' => ['A321041C8EAD8108AF9D5AD50F442FC2'], |
|||
//设置买单结算方式功能 |
|||
'payOlSetStatus' => ['178FBB14D1DB9A63F0EF6E18AD8DE5E7','569A3DCF87F3514FD5EBCE07D4E48F73','C4E6BF7978DA38FBDA080E17F06B74FE'], |
|||
//收益到账模板消息通知 |
|||
'customized530' => ['E42B66E240ED831B957640A4C7DB2B70','C4E6BF7978DA38FBDA080E17F06B74FE'], |
|||
//幸运团 |
|||
'luckygroup' => ['1047AE3ECA2D800F7A1BA6BF1A1B05D3','09B945EDB70F2F1FF74D1859D2C4A7A8'], |
|||
//余额返现 |
|||
'yuecashback' => ['C4E6BF7978DA38FBDA080E17F06B74FE','08E2DDB0633F37A36E122E287F3F409F','8A8A9A64918A37456A82F7669CFE2394','1047AE3ECA2D800F7A1BA6BF1A1B05D3'], |
|||
//共享股东文本替换 |
|||
'distributionText' => ['4897239A840F136884F18CC32F72C60F'], |
|||
//云收单-微信支付 |
|||
'yunmis160' => ['2A83006129E758100E2184B2E8DF26BF'], |
|||
//147定制 |
|||
'pft147' => ['FFBB7D90AFC418BAF94310747ACC6815'], |
|||
//转赠定制 |
|||
'transfergift' => ['AFFD1B0DF199A71EF6B2232E3B057E63','C4E6BF7978DA38FBDA080E17F06B74FE','1047AE3ECA2D800F7A1BA6BF1A1B05D3'], |
|||
//掌上信息绑定商户和视频付费查阅 |
|||
'pocket1500' => ['1047AE3ECA2D800F7A1BA6BF1A1B05D3','C4E6BF7978DA38FBDA080E17F06B74FE','E16627FFC9A6CE60B82A1B7AF8214CA8'], |
|||
//掌上信息全局推广功能 |
|||
'pocket140' => ['8A8A9A64918A37456A82F7669CFE2394'], |
|||
//名片页面文本修改 |
|||
'citycard1503' => ['1047AE3ECA2D800F7A1BA6BF1A1B05D3','C4E6BF7978DA38FBDA080E17F06B74FE','A56EA6E46481D9AD18080EB2243083FB'], |
|||
//1512上传 |
|||
'upfile1512' => ['1047AE3ECA2D800F7A1BA6BF1A1B05D3','BF749328FBA75ED8F56BA8B4BB92F2A8'], |
|||
//1520商户二级页面 |
|||
'storecate1520' => ['1047AE3ECA2D800F7A1BA6BF1A1B05D3','B26A8E91BF4F990F2F8A16816F4C5C1C'], |
|||
//074积分定制 |
|||
'integral074' => ['E8FB5DC83D1618526E4AEFA1F5FC998D'], |
|||
//735隐藏内定 |
|||
'priest735' => ['452B79B26E82E151AB19C8A8765DD08C'], |
|||
//1543语言包定制 |
|||
'language1543' => ['813C1C014FA2C93DCC19908C09609B9F'] |
|||
]; |
|||
//默认授权码 拥有所有功能 |
|||
//$default = ['1047AE3ECA2D800F7A1BA6BF1A1B05D3']; |
|||
$default = []; |
|||
return array_merge($list[$name],$default); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
@ -0,0 +1,244 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Dashboard { |
|||
/////////////////////////////////////////////////////首页参数设置///////////////////////////////////////////////////////////// |
|||
/* |
|||
* 读取参数 |
|||
*/ |
|||
static function readSetting($key) { |
|||
global $_W; |
|||
$settings = pdo_get(PDO_NAME . 'indexset', array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']), array('value')); |
|||
if (is_array($settings)) { |
|||
$settings = iunserializer($settings['value']); |
|||
} else { |
|||
$settings = array(); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
/* |
|||
* 保存参数 |
|||
*/ |
|||
static function saveSetting($data, $key) { |
|||
global $_W; |
|||
if (empty($key)) return FALSE; |
|||
$record = array(); |
|||
$record['value'] = iserializer($data); |
|||
|
|||
$exists = pdo_getcolumn(PDO_NAME . 'indexset', array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']), 'id'); |
|||
if ($exists) { |
|||
$return = pdo_update(PDO_NAME . 'indexset', $record, array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
} else { |
|||
$record['key'] = $key; |
|||
$record['uniacid'] = $_W['uniacid']; |
|||
$record['aid'] = $_W['aid']; |
|||
$return = pdo_insert(PDO_NAME . 'indexset', $record); |
|||
} |
|||
return $return; |
|||
} |
|||
|
|||
/////////////////////////////////////////////////////幻灯片///////////////////////////////////////////////////////////// |
|||
/* |
|||
* 查询所有幻灯片 |
|||
*/ |
|||
static function getAllAdv($page = 0, $pagenum = 10, $enabled = '', $type = '', $namekey = '') { |
|||
global $_W; |
|||
$condition = ''; |
|||
if (!empty($enabled) && $enabled != '') $condition = " and enabled=" . $enabled; |
|||
if ($type == -1) { |
|||
$condition .= " and type = 0"; |
|||
} else if ($type) { |
|||
$condition .= " and type=" . $type; |
|||
} |
|||
if ($namekey) $condition = " and advname like '%" . $namekey . "%'"; |
|||
$re['data'] = pdo_fetchall("select * from" . tablename(PDO_NAME . 'adv') . " where uniacid=:uniacid and aid=:aid " . $condition . " order by type asc,enabled desc,displayorder desc limit " . $page * $pagenum . "," . $pagenum, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
$re['count'] = pdo_fetchcolumn("select count(*) from" . tablename(PDO_NAME . 'adv') . "where uniacid=:uniacid and aid=:aid " . $condition, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
return $re; |
|||
} |
|||
|
|||
/* |
|||
* 编辑幻灯片 |
|||
*/ |
|||
static function editAdv($arr, $id = '') { |
|||
global $_W; |
|||
if (empty($arr)) return false; |
|||
if (!empty($id) && $id != '') return pdo_update(PDO_NAME . 'adv', $arr, array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
$arr['aid'] = $_W['aid']; |
|||
$arr['uniacid'] = $_W['uniacid']; |
|||
return pdo_insert(PDO_NAME . 'adv', $arr); |
|||
} |
|||
|
|||
/* |
|||
* 获取单条幻灯片详情 |
|||
*/ |
|||
static function getSingleAdv($id) { |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
return pdo_get(PDO_NAME . 'adv', array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
} |
|||
|
|||
|
|||
/////////////////////////////////////////////////////导航栏///////////////////////////////////////////////////////////// |
|||
/* |
|||
* 查询所有导航栏 |
|||
*/ |
|||
static function getAllNav($page = 0, $pagenum = 10, $enabled = '', $merchantid = '') { |
|||
global $_W; |
|||
$condition = ''; |
|||
if (!empty($enabled) && $enabled != '') $condition = " and enabled=" . $enabled; |
|||
if (!empty($merchantid) && $merchantid != '') { |
|||
$condition = " and merchantid=" . $merchantid; |
|||
} else { |
|||
$condition = " and merchantid= 0"; |
|||
} |
|||
$re['data'] = pdo_fetchall("select * from" . tablename(PDO_NAME . 'nav') . "where uniacid=:uniacid and aid=:aid " . $condition . " order by enabled desc, displayorder desc limit " . $page * $pagenum . "," . $pagenum, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
$re['count'] = pdo_fetchcolumn("select count(*) from" . tablename(PDO_NAME . 'nav') . "where uniacid=:uniacid and aid=:aid " . $condition, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
return $re; |
|||
} |
|||
|
|||
/* |
|||
* 编辑导航栏 |
|||
*/ |
|||
static function editNav($arr, $id = '') { |
|||
global $_W; |
|||
if (empty($arr)) return false; |
|||
if (!empty($id) && $id != '') return pdo_update(PDO_NAME . 'nav', $arr, array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
$arr['aid'] = $_W['aid']; |
|||
$arr['uniacid'] = $_W['uniacid']; |
|||
return pdo_insert(PDO_NAME . 'nav', $arr); |
|||
} |
|||
|
|||
/* |
|||
* 获取单条导航栏详情 |
|||
*/ |
|||
static function getSingleNav($id) { |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
return pdo_get(PDO_NAME . 'nav', array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
} |
|||
|
|||
/////////////////////////////////////////////////////广告位///////////////////////////////////////////////////////////// |
|||
/* |
|||
* 查询所有广告位 |
|||
*/ |
|||
static function getAllBanner($page = 0, $pagenum = 10, $enabled = '') { |
|||
global $_W; |
|||
$condition = ''; |
|||
if (!empty($enabled) && $enabled != '') $condition = " and enabled=" . $enabled; |
|||
$re['data'] = pdo_fetchall("select * from" . tablename(PDO_NAME . 'banner') . "where uniacid=:uniacid and aid=:aid " . $condition . " order by enabled desc, displayorder desc limit " . $page * $pagenum . "," . $pagenum, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
$re['count'] = pdo_fetchcolumn("select count(*) from" . tablename(PDO_NAME . 'banner') . "where uniacid=:uniacid and aid=:aid " . $condition, array(':uniacid' => $_W['uniacid'], ':aid' => $_W['aid'])); |
|||
return $re; |
|||
} |
|||
|
|||
/* |
|||
* 编辑广告位 |
|||
*/ |
|||
static function editBanner($arr, $id = '') { |
|||
global $_W; |
|||
if (empty($arr)) return false; |
|||
if (!empty($id) && $id != '') return pdo_update(PDO_NAME . 'banner', $arr, array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
$arr['aid'] = $_W['aid']; |
|||
$arr['uniacid'] = $_W['uniacid']; |
|||
return pdo_insert(PDO_NAME . 'banner', $arr); |
|||
} |
|||
|
|||
/* |
|||
* 获取单条广告位详情 |
|||
*/ |
|||
static function getSingleBanner($id) { |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
return pdo_get(PDO_NAME . 'banner', array('id' => $id, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
} |
|||
|
|||
|
|||
/* |
|||
* 获取手机端首页数据 |
|||
*/ |
|||
static function get_app_data() { |
|||
global $_W; |
|||
$default_page = array( |
|||
array('on' => 1, 'sort' => 'search'), |
|||
array('on' => 1, 'sort' => 'adv'), |
|||
array('on' => 1, 'sort' => 'nav'), |
|||
array('on' => 1, 'sort' => 'notice'), |
|||
array('on' => 1, 'sort' => 'banner'), |
|||
array('on' => 1, 'sort' => 'cube'), |
|||
array('on' => 1, 'sort' => 'nearby') |
|||
); |
|||
$load_page = self::readSetting('sort'); |
|||
$page = !empty($load_page) ? $load_page : $default_page; |
|||
$advs = pdo_getall(PDO_NAME . 'adv', array('enabled' => 1, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'], 'type' => 0)); |
|||
$nav = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . 'nav') . " WHERE enabled = 1 and merchantid = 0 and uniacid = '{$_W['uniacid']}' and aid = {$_W['aid']} ORDER BY displayorder DESC"); |
|||
$banner = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . 'banner') . " WHERE enabled = 1 and uniacid = '{$_W['uniacid']}' and aid = {$_W['aid']} ORDER BY displayorder DESC"); |
|||
$notice = pdo_fetchall("SELECT * FROM " . tablename(PDO_NAME . 'notice') . " WHERE enabled = 1 and uniacid = '{$_W['uniacid']}' and aid = {$_W['aid']} ORDER BY id DESC"); |
|||
$cubes = self::readSetting('cube'); |
|||
foreach ($cubes as $k => $v) { |
|||
if (empty($v['thumb']) || $v['on'] == 0) { |
|||
unset($cubes[$k]); |
|||
} |
|||
} |
|||
$cubes = array_merge($cubes); |
|||
return array('page' => $page, 'adv' => $advs, 'nav' => $nav, 'banner' => $banner, 'notice' => $notice, 'cubes' => $cubes); |
|||
} |
|||
|
|||
static function set_agent_cookie($aid, $type = 'aid') { |
|||
global $_W, $_GPC; |
|||
$where = " a.uniacid = {$_W['uniacid']} AND a.status = 1 "; |
|||
if ($type == 'aid') { |
|||
$where .= " AND a.aid = " . $aid; |
|||
} else { |
|||
$where .= " AND a.areaid = " . $aid; |
|||
} |
|||
$oparea = pdo_fetch("SELECT a.areaid,a.aid,b.name,b.level,b.pid FROM " . tablename(PDO_NAME . "oparea") . " a LEFT JOIN " . tablename(PDO_NAME . "area") . " b ON a.areaid = b.id WHERE " . $where); |
|||
if (empty($oparea)) { |
|||
return error(1, '当前地区无代理'); |
|||
} |
|||
|
|||
//非总后台判断代理状态和时间 |
|||
if (!empty($oparea['aid'])) { |
|||
$agent = pdo_get(PDO_NAME . 'agentusers', array('id' => $oparea['aid'], 'uniacid' => $_W['uniacid']), array('status', 'endtime')); |
|||
if ($agent['endtime'] < time()) { |
|||
return error(1, '当前地区代理已过期'); |
|||
} |
|||
if ($agent['status'] != 1) { |
|||
return error(1, '当前地区未启用'); |
|||
} |
|||
} |
|||
|
|||
//如果存在详细地点则区域显示详细地点,否则显示区域城市信息 |
|||
$locateInfo = wl_getcookie('locate_information'); |
|||
if ($_W['wlsetting']['areaset']['location'] == 1 && is_array($locateInfo) && !empty($locateInfo)) { |
|||
$_W['location']['lat'] = $locateInfo['lat']; |
|||
$_W['location']['lng'] = $locateInfo['lng']; |
|||
} |
|||
|
|||
$_W['aid'] = $oparea['aid']; |
|||
$_W['areaid'] = $oparea['areaid']; |
|||
$_W['citycode'] = $locateInfo['citycode'] ? $locateInfo['citycode'] : self::get_city_code($oparea['areaid'], $oparea['level'], $oparea['pid']); |
|||
$_W['areaname'] = (!empty($locateInfo['title']) && $_W['wlsetting']['areaset']['location'] == 1) ? $locateInfo['title'] : $oparea['name']; |
|||
|
|||
wl_setcookie("agentareaid", $_W['areaid'], 30 * 86400); |
|||
return TRUE; |
|||
} |
|||
|
|||
static function get_city_code($areaid, $level, $pid) { |
|||
switch ($level) { |
|||
case 1: |
|||
$city = (new AreaTable())->selectFields('id')->where('pid', $areaid)->get(); |
|||
$citycode = $city['id']; |
|||
break; |
|||
case 2: |
|||
$citycode = $areaid; |
|||
break; |
|||
case 3: |
|||
$citycode = $pid; |
|||
break; |
|||
default: |
|||
$city = (new AreaTable())->selectFields('pid')->where('id', $pid)->get(); |
|||
$citycode = $city['id']; |
|||
} |
|||
return $citycode; |
|||
} |
|||
} |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,18 @@ |
|||
<?php |
|||
/** |
|||
* TODO 补充说明 |
|||
* |
|||
* User: jiehua |
|||
* Date: 16/3/30 |
|||
* Time: 下午8:55 |
|||
*/ |
|||
|
|||
class EncryptParseItem |
|||
{ |
|||
public $startIndex; |
|||
|
|||
public $endIndex; |
|||
|
|||
public $encryptContent; |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
<?php |
|||
/** |
|||
* TODO 补充说明 |
|||
* |
|||
* User: jiehua |
|||
* Date: 16/3/30 |
|||
* Time: 下午8:51 |
|||
*/ |
|||
|
|||
class EncryptResponseData |
|||
{ |
|||
public $realContent; |
|||
|
|||
public $returnContent; |
|||
|
|||
} |
|||
@ -0,0 +1,109 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
/** |
|||
* Comment: 信息过滤 |
|||
* Author: zzw |
|||
* Class Filter.mod |
|||
*/ |
|||
class Filter { |
|||
protected static $content, |
|||
$source, |
|||
$ar;//信息内容 |
|||
|
|||
/** |
|||
* Comment: 信息过滤初始化 |
|||
* Author: zzw |
|||
* Date: 2019/12/31 18:24 |
|||
* @param string|array $content |
|||
* @param int $source 1=公众号(默认);2=h5;3=小程序 |
|||
* @param int $type 1=文本信息,2=图片信息 |
|||
* @return array |
|||
*/ |
|||
public static function init($content,$source = 1,$type = 1){ |
|||
#source:1=公众号(默认);2=h5;3=小程序 |
|||
#type:1=文本信息,2=图片信息 |
|||
self::$content = $content; |
|||
self::$source = $source; |
|||
#1、端口信息转换 |
|||
if (self::$source == 3) $sourceName = 'wxApp';//小程序 |
|||
else $sourceName = 'weChat';//公众号、H5 |
|||
#2、过滤信息类型转换 |
|||
if ($type == 1) $typeName = 'Text';//文本信息 |
|||
else if ($type == 2) $typeName = 'Image';//图片信息 |
|||
else return error(0,'信息类型错误'); |
|||
#3、调用方法进行信息过滤 |
|||
$method = $sourceName.$typeName; |
|||
return self::$method(); |
|||
} |
|||
|
|||
/****** 小程序信息过滤 ***********************************************************************************************/ |
|||
/** |
|||
* Comment: 小程序 - 文本信息过滤 |
|||
* Author: zzw |
|||
* Date: 2020/1/3 9:57 |
|||
* @param bool $state |
|||
* @return array |
|||
*/ |
|||
protected static function wxAppText($state = false){ |
|||
#1、基本参数配置 |
|||
$accessToken = WeliamWeChat::getAccessToken($state , self::$source); |
|||
$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token={$accessToken}"; |
|||
#2、调用接口进行信息判断 |
|||
$result = curlPostRequest($url , json_encode(['content' => self::$content] , JSON_UNESCAPED_UNICODE)); |
|||
|
|||
if($result['errcode'] == 40001) self::wxAppText(true); |
|||
elseif ($result['errcode'] == 0 || $result['errcode'] == 48001) return error(1,$result['errmsg']); |
|||
elseif ($result['errcode'] == 87014) return error(0,'含有敏感或非法内容,请修改后提交!'); |
|||
else return error(0,$result['errmsg']); |
|||
} |
|||
/** |
|||
* Comment: 小程序 - 图片信息过滤 |
|||
* Author: zzw |
|||
* Date: 2020/1/3 10:53 |
|||
* @param bool $state |
|||
* @return array |
|||
*/ |
|||
protected static function wxAppImage($state = false){ |
|||
global $_W; |
|||
#1、基本参数配置 |
|||
$accessToken = WeliamWeChat::getAccessToken($state , self::$source); |
|||
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token={$accessToken}"; |
|||
#2、图片资源转换 |
|||
$obj = new CURLFile(realpath(self::$content)); |
|||
$obj->setMimeType("image/jpeg"); |
|||
$file['media'] = $obj; |
|||
$result = curlPostRequest($url , $file); |
|||
if($result['errcode'] == 40001) self::wxAppText(true); |
|||
elseif ($result['errcode'] == 0 || $result['errcode'] == 48001 || $result['errcode'] == 45002) return error(1,'成功'); // 48001 api功能未授权 45002 消息内容超过限制(上传图片超出2M) |
|||
elseif ($result['errcode'] == 87014) return error(0,'非法图片'); |
|||
else return error(0,$result['errmsg']); |
|||
} |
|||
|
|||
|
|||
/****** 公众号信息过滤 ***********************************************************************************************/ |
|||
//公众号 - 文本信息过滤 - 开发中 |
|||
protected static function weChatText(){ |
|||
#1、判断如果存在 小程序并且进行了信息配置 则使用小程序过滤信息 |
|||
$set = Setting::wlsetting_read('wxapp_config'); |
|||
if(p('wxapp') && is_array($set) && $set['appid']){ |
|||
self::$source = 3; |
|||
return self::wxAppText(true); |
|||
} |
|||
|
|||
|
|||
return error(1,'成功'); |
|||
} |
|||
//公众号 - 图片信息过滤 - 开发中 |
|||
protected static function weChatImage(){ |
|||
#1、判断如果存在 小程序并且进行了信息配置 则使用小程序过滤信息 |
|||
$set = Setting::wlsetting_read('wxapp_config'); |
|||
if(p('wxapp') && is_array($set) && $set['appid']){ |
|||
self::$source = 3; |
|||
return self::wxAppImage(true); |
|||
} |
|||
|
|||
return error(1,'成功'); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
/** |
|||
* Comment: 模板消息操作模型 |
|||
* Author: zzw |
|||
* Class Template |
|||
*/ |
|||
class FollowWaybill |
|||
{ |
|||
|
|||
public static function followWaybill($nowToken = false) |
|||
{ |
|||
global $_W; |
|||
|
|||
$member = pdo_get(PDO_NAME . 'member',['id' => $_W['mid']],['openid']); |
|||
|
|||
try { |
|||
$accessToken = WeliamWeChat::getAccessToken($nowToken); //token信息获取 |
|||
$http = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/follow_waybill?access_token={$accessToken}"; |
|||
$data = [ |
|||
'openid' => trim($member['openid']), |
|||
'sender_phone' => '', |
|||
'receiver_phone' => '', |
|||
'delivery_id' => '', |
|||
'waybill_id' => '', |
|||
'goods_info' => [], |
|||
'trans_id' => '', |
|||
'order_detail_path' => '', |
|||
]; |
|||
$headers = [ |
|||
"Content-type: application/json;charset='utf-8'" , |
|||
"Accept: application/json" , |
|||
"Cache-Control: no-cache" , |
|||
"Pragma: no-cache" |
|||
]; |
|||
$res = curlPostRequest($http,\GuzzleHttp\json_encode($data,JSON_UNESCAPED_UNICODE),$headers); |
|||
} catch ($e) { |
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,322 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
/** |
|||
* Comment: 通讯信息操作模型 |
|||
* Author: zzw |
|||
* Class Im |
|||
*/ |
|||
class Im { |
|||
protected static $table = PDO_NAME."im"; |
|||
/** |
|||
* Comment: 获取通讯分组列表 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 9:44 |
|||
* @param $id int 信息接收人id |
|||
* @param $type int 信息接收人类型(1=用户;2=商户) |
|||
* @param $page int 当前页;默认1 |
|||
* @param $pageIndex int 每页的数量;默认10 |
|||
* @return mixed array |
|||
*/ |
|||
public static function myList($id,$type,$page = 1,$pageIndex = 10,$plugin = '',$is_store = false){ |
|||
global $_W; |
|||
#1、sql语句生成 |
|||
$where = " (receive_id = {$id} AND `receive_type` = {$type}) OR (`send_id` = {$id} AND `send_type` = {$type}) "; |
|||
if ($is_store) { |
|||
$storeid = pdo_getcolumn(PDO_NAME.'merchantuser',['mid' => $_W['mid']],'storeid'); |
|||
if ($storeid) { |
|||
$where .= " OR (receive_id = {$storeid} AND `receive_type` = 2) OR (`send_id` = {$storeid} AND `send_type` = 2) "; |
|||
} |
|||
} |
|||
if($plugin) $where .= " AND plugin = {$plugin} "; |
|||
else $where .= " AND (plugin = '' OR plugin IS NULL)"; |
|||
$sql = "SELECT max(id) as id,receive_type,plugin,send_type,FROM_UNIXTIME(max(create_time),'%Y-%m-%d %H:%i:%S') as date_time, |
|||
CASE WHEN receive_id = {$id} AND `receive_type` = {$type} THEN `send_id` |
|||
ELSE `receive_id` |
|||
END as other_party_id, |
|||
CASE WHEN receive_id = {$id} AND `receive_type` = {$type} THEN `send_type` |
|||
ELSE `receive_type` |
|||
END as other_party_type, |
|||
(SELECT COUNT(*) FROM ".tablename(PDO_NAME.'im')." as t |
|||
WHERE t.`send_id` = other_party_id AND t.`send_type` = other_party_type |
|||
AND t.`receive_id` = {$id} AND t.`receive_type` = {$type} AND t.`is_read` = 0) as total, |
|||
CONCAT_WS('_', |
|||
CASE WHEN receive_id = {$id} AND `receive_type` = {$type} THEN `send_id` |
|||
ELSE `receive_id` |
|||
END |
|||
, |
|||
CASE WHEN receive_id = {$id} AND `receive_type` = {$type} THEN `send_type` |
|||
ELSE `receive_type` |
|||
END |
|||
) as group_name |
|||
FROM ".tablename(PDO_NAME.'im')." |
|||
WHERE {$where} GROUP BY group_name ORDER BY date_time DESC "; |
|||
#2、总数获取 |
|||
$list = pdo_fetchall($sql) ? : []; |
|||
$data['total'] = ceil(count($list) / $pageIndex); |
|||
#3、分页操作 |
|||
$startPage = $page * $pageIndex - $pageIndex; |
|||
$data['list'] = array_slice($list,$startPage,$pageIndex); |
|||
#4、循环处理数据信息 |
|||
foreach($data['list'] as $key => &$val){ |
|||
//获取最新的消息信息 |
|||
$val['content'] = pdo_getcolumn(PDO_NAME."im" ,['id'=>$val['id']],'content'); |
|||
$val['content'] = self::base64Processing($val['content']); |
|||
$val['type'] = pdo_getcolumn(PDO_NAME."im" ,['id'=>$val['id']],'type'); |
|||
//获取聊天对象信息 |
|||
if($val['other_party_type'] == 1){ |
|||
//聊天对象:用户 |
|||
// $info = pdo_get(PDO_NAME . "member" , [ 'id' => $val['other_party_id'] ] , [ 'nickname' , 'avatar' ]); |
|||
// $val['nickname'] = $info['nickname']; |
|||
// $val['avatar'] = $info['avatar']; |
|||
Member::getMemberInfo($val,$val['other_party_id']); |
|||
} else { |
|||
//聊天对象:商户 |
|||
$info = pdo_get(PDO_NAME."merchantdata",['id'=>$val['other_party_id']],['storename','logo']); |
|||
$val['nickname'] = $info['storename']; |
|||
$val['avatar'] = tomedia($info['logo']); |
|||
} |
|||
//删除多余的数据信息 |
|||
unset($val['receive_type']); |
|||
unset($val['group_name']); |
|||
} |
|||
|
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 保存通讯信息 |
|||
* Author: zzw |
|||
* Date: 2019/8/26 15:45 |
|||
* @param array $data |
|||
* @return bool |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException |
|||
*/ |
|||
public static function insert(array $data){ |
|||
$endTime = self::caCheImInfo($data,2); |
|||
if($endTime < time()){ |
|||
//通讯时间节点过期 当前发送信息用户未收到 |
|||
self::sendImModelInfo($data); |
|||
} |
|||
return pdo_insert(self::$table,$data); |
|||
} |
|||
/** |
|||
* Comment: 获取通讯记录 |
|||
* Author: zzw |
|||
* Date: 2019/8/26 17:34 |
|||
* @param $page |
|||
* @param $pageIndex |
|||
* @param $thisId |
|||
* @param $thisType |
|||
* @param $otherPartyType |
|||
* @param $otherPartyId |
|||
* @return mixed |
|||
*/ |
|||
public static function imRecord($page,$pageIndex,$sendInfo){ |
|||
global $_W,$_GPC; |
|||
$plugin = $_GPC['plugin'] ? : ''; |
|||
#1、缓存通讯时间节点 |
|||
self::caCheImInfo($sendInfo); |
|||
#1、分页 |
|||
$pageStart = $page * $pageIndex - $pageIndex; |
|||
#2、条件生成 |
|||
$where = " as a WHERE a.uniacid = {$_W['uniacid']} AND |
|||
( |
|||
(a.send_id = {$sendInfo['send_id']} AND a.send_type = {$sendInfo['send_type']} AND a.receive_id = {$sendInfo['receive_id']} AND a.receive_type = {$sendInfo['receive_type']}) |
|||
OR |
|||
(a.send_id = {$sendInfo['receive_id']} AND a.send_type = {$sendInfo['receive_type']} AND a.receive_id = {$sendInfo['send_id']} AND a.receive_type = {$sendInfo['send_type']}) |
|||
)"; |
|||
if($plugin) $where .= " AND a.plugin = {$plugin} "; |
|||
else $where .= " AND (a.plugin = '' OR a.plugin IS NULL)"; |
|||
#3、要查询的字段生成 |
|||
$field = " a.id,a.send_id,a.`send_type`,a.`receive_id`,a.content,a.plugin,a.create_time,a.type,FROM_UNIXTIME(create_time,'%Y-%m-%d %H:%i:%S') as date_time, |
|||
CASE a.`send_type` |
|||
WHEN 1 THEN (SELECT `nickname` FROM ".tablename(PDO_NAME."member")." WHERE `id` = a.`send_id`) |
|||
ELSE (SELECT storename FROM ".tablename(PDO_NAME."merchantdata")." WHERE `id` = a.`send_id` ) |
|||
END as nickname, |
|||
CASE a.`send_type` |
|||
WHEN 1 THEN (SELECT `avatar` FROM ".tablename(PDO_NAME."member")." WHERE `id` = a.`send_id`) |
|||
ELSE (SELECT logo FROM ".tablename(PDO_NAME."merchantdata")." WHERE `id` = a.`send_id` ) |
|||
END as avatar"; |
|||
#4、获取总页数 |
|||
$totalSql = "SELECT COUNT(*) FROM ".tablename(self::$table).$where; |
|||
$total = pdo_fetchcolumn($totalSql); |
|||
$data['total'] = ceil($total / $pageIndex); |
|||
#5、获取当前页列表信息 |
|||
$sql = "SELECT {$field} FROM ".tablename(self::$table).$where |
|||
." ORDER BY a.create_time DESC LIMIT {$pageStart},{$pageIndex} "; |
|||
$data['list'] = pdo_fetchall($sql); |
|||
foreach($data['list'] as $key => &$val) { |
|||
$val['avatar'] = tomedia($val['avatar']); |
|||
$val['content'] = self::base64Processing($val['content']); |
|||
$val['is_my'] = 0; |
|||
if ($sendInfo['receive_id'] == $val['send_id'] && $val['send_type'] == $sendInfo['receive_type']) { |
|||
$val['is_my'] = 1; |
|||
} |
|||
} |
|||
|
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 修改数据 |
|||
* Author: zzw |
|||
* Date: 2019/8/27 9:07 |
|||
* @param $data |
|||
* @param $where |
|||
* @return bool |
|||
*/ |
|||
public static function is_read($ids,$thisId = 0){ |
|||
global $_W; |
|||
#1、条件生成 |
|||
if(!empty($thisId)){ |
|||
$where = " receive_id = {$thisId} "; |
|||
}else{ |
|||
$where = " receive_id = {$_W['mid']} "; |
|||
} |
|||
if(count($ids) > 1){ |
|||
$idStr = implode(',',$ids); |
|||
$where .= " AND id IN ({$idStr}) "; |
|||
}else{ |
|||
$where .= " AND id = {$ids[0]} "; |
|||
} |
|||
#2、修改内容 |
|||
return pdo_query(" UPDATE ".tablename(self::$table)." SET is_read = 1 WHERE ".$where); |
|||
} |
|||
/** |
|||
* Comment: 通讯时间节点信息 |
|||
* Author: zzw |
|||
* Date: 2019/11/26 11:11 |
|||
* @param array $data |
|||
* @param int $status 1=set;2=get |
|||
* @return array|bool|false|Memcache|mixed|Redis|string|true |
|||
*/ |
|||
protected static function caCheImInfo($data,$status = 1){ |
|||
# 思路: |
|||
# 储存:时按照正常参数 储存通讯时间节点信息 |
|||
# 获取:时所有参数调换 即发送信息变更为接收方信息 接收方信息变更为发送方信息 |
|||
#1、基本信息生成 |
|||
$caCheKey = 'im_info';//缓存名称 |
|||
$statusTime = 15;//聊天状态保存时间,改时间内未获取请求信息 则未进入聊天状态 |
|||
#2、根据操作类型进行对应的操作 |
|||
if($status == 1){ |
|||
//储存当前请求用户的通讯时间节点信息 |
|||
$caCheName = md5('id'.$data['send_id'].'type'.$data['send_type'].'other_id'.$data['receive_id'].'other_type'.$data['receive_type']); |
|||
$endTime = intval(time() + $statusTime); |
|||
$res = Cache::setCache($caCheKey,$caCheName,$endTime); |
|||
}else{ |
|||
$caCheName = md5('id'.$data['receive_id'].'type'.$data['receive_type'].'other_id'.$data['send_id'].'other_type'.$data['send_type']); |
|||
$res = Cache::getCache($caCheKey,$caCheName); |
|||
} |
|||
return intval($res); |
|||
} |
|||
/** |
|||
* Comment: 发送通讯消息提醒模板 |
|||
* Author: zzw |
|||
* Date: 2019/11/26 14:09 |
|||
* @param $data |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
protected static function sendImModelInfo($data){ |
|||
global $_W; |
|||
# 思路:判断接收消息的用户是否在聊天室中,所以以接收方信息为主 判断接收方类型 获取接收模板消息的用户的openid |
|||
# $data['send_id'] 发送方id |
|||
# $data['send_type'] 发送方类型(1=用户;2=商户) |
|||
# $data['receive_id'] 接收人id |
|||
# $data['receive_type'] 接收人类型(1=用户;2=商户) |
|||
#1、获取发送方信息 |
|||
if($data['send_type'] == 1){ |
|||
//消息发送方为用户 |
|||
$sendUser = pdo_get(PDO_NAME."member",['id'=>$data['send_id']],['nickname']); |
|||
$first = '您好,用户[' . $sendUser['nickname'] . ']向您发送了通讯消息'; |
|||
}else{ |
|||
//消息发送方为商户 |
|||
$sendShop = pdo_get(PDO_NAME."merchantdata",['id'=>$data['send_id']],['storename']); |
|||
$first = '您好,商户[' . $sendShop['storename'] . ']向您发送了通讯消息'; |
|||
} |
|||
if(empty($data['type'])){ |
|||
$content = '文本消息'; |
|||
}else if($data['type'] == 1){ |
|||
$content = '图片消息'; |
|||
}else if($data['type'] == 2){ |
|||
$content = '视频消息'; |
|||
}else if($data['type'] == 3){ |
|||
$content = '个人名片'; |
|||
}else if($data['type'] == 4){ |
|||
$content = '个人简历'; |
|||
} |
|||
|
|||
#1、生成模板配置信息 |
|||
$modelData = [ |
|||
'first' => $first, |
|||
'type' => '消息提醒',//业务类型 |
|||
'content' => $content,//业务内容 |
|||
'status' => '未读' ,//处理结果 |
|||
'time' => date("Y-m-d H:i:s",$data['create_time']) ,//操作时间 |
|||
'remark' => '请尽快进行回复' |
|||
]; |
|||
#1、生成链接信息 |
|||
$link = h5_url('pagesA/instantMessenger/instantMessenger' , [ |
|||
'id' => $data['receive_id'] , |
|||
'type' => $data['receive_type'], |
|||
'other_party_id' => $data['send_id'], |
|||
'other_party_type' => $data['send_type'] |
|||
]); |
|||
#2、根据消息接收方类型 分别发送模板消息 |
|||
if($data['receive_type'] == 1){ |
|||
//接收消息方为用户时 |
|||
$res = TempModel::sendInit('service',$data['receive_id'] ,$modelData,$_W['source'],$link); |
|||
}else{ |
|||
//接收消息方为商户时 |
|||
$list = pdo_fetchall("SELECT id,mid FROM ".tablename(PDO_NAME."merchantuser") |
|||
." WHERE storeid = {$data['receive_id']} AND enabled = 1 AND ismain IN (1,3)"); |
|||
if(is_array($list) && count($list) > 0){ |
|||
foreach($list as $key => &$val){ |
|||
TempModel::sendInit('service',$val['mid'],$modelData,$_W['source'],$link); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 清除某个对话的所有通信记录 |
|||
* Author: zzw |
|||
* Date: 2020/9/10 11:25 |
|||
* @param $sendId |
|||
* @param $receiveId |
|||
* @return bool|mixed |
|||
*/ |
|||
public function deleteRecord($sendId,$receiveId){ |
|||
//条件生成 |
|||
$where = " WHERE (send_id = {$sendId} && receive_id = {$receiveId}) OR (send_id = {$receiveId} && receive_id = {$sendId})"; |
|||
//删除操作 |
|||
$sql = "DELETE FROM ".tablename(self::$table).$where; |
|||
|
|||
return pdo_query($sql); |
|||
} |
|||
/** |
|||
* Comment: 通讯内容信息处理(base64处理) |
|||
* Author: zzw |
|||
* Date: 2021/4/6 16:13 |
|||
* @param string $content |
|||
* @return false|mixed|string |
|||
*/ |
|||
protected static function base64Processing($content){ |
|||
if(is_base64($content) && json_encode(base64_decode($content,true),JSON_UNESCAPED_UNICODE)) { |
|||
$content = base64_decode($content,true); |
|||
} |
|||
|
|||
return $content; |
|||
} |
|||
/** |
|||
* 判断用户是否存在已读数据 |
|||
* @param $id // 用户ID 或是 商户ID |
|||
* @param $type // 1 = 用户 2 = 商户 |
|||
* @return false|mixed |
|||
*/ |
|||
public static function isRandInfo($id,$type = 1) |
|||
{ |
|||
$where = "is_read = 0 and (receive_id = {$id} AND `receive_type` = {$type}) OR (`send_id` = {$id} AND `send_type` = {$type}) "; |
|||
$sql = 'select id from ' . tablename(PDO_NAME . 'im') . ' where ' . $where . ' limit 1'; |
|||
$result = pdo_fetch($sql); |
|||
return $result ? true : false; |
|||
} |
|||
} |
|||
@ -0,0 +1,646 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Links { |
|||
/** |
|||
* Comment: 获取公共链接基本链接信息 |
|||
* Author: zzw |
|||
* Date: 2019/9/6 9:50 |
|||
* @param string $state |
|||
* @return array |
|||
*/ |
|||
public static function getLinks($state = '*') { |
|||
global $_W; |
|||
#1、系统链接 - 基础链接 |
|||
$system = [ |
|||
'basic' => [ |
|||
'name' => '基本链接', |
|||
'list' => [ |
|||
['name' => '首页入口', 'url' => h5_url('pages/mainPages/index/index'), 'page_path' => 'pages/mainPages/index/index'], |
|||
['name' => '好店入口', 'url' => h5_url('pages/mainPages/index/diypage?type=8'), 'page_path' => 'pages/mainPages/index/diypage?type=8'], |
|||
['name' => '一卡通首页', 'url' => h5_url('pages/mainPages/memberCard/memberCard'), 'page_path' => 'pages/mainPages/memberCard/memberCard'], |
|||
['name' => '商户入驻', 'url' => h5_url('pages/mainPages/Settled/Settled'), 'page_path' => 'pages/mainPages/Settled/Settled'], |
|||
['name' => '商户中心', 'url' => h5_url('pages/subPages/merchant/merchantChangeShop/merchantChangeShop'), 'page_path' => 'pages/subPages/merchant/merchantChangeShop/merchantChangeShop'], |
|||
['name' => '个人中心', 'url' => h5_url('pages/mainPages/userCenter/userCenter'), 'page_path' => 'pages/mainPages/userCenter/userCenter'], |
|||
['name' => '我的订单', 'url' => h5_url('pages/subPages/orderList/orderList?status=10'), 'page_path' => 'pages/subPages/orderList/orderList?status=10'], |
|||
['name' => '帮助中心', 'url' => h5_url('pages/subPages/helpCenter/helpCenter'), 'page_path' => 'pages/subPages/helpCenter/helpCenter'], |
|||
['name' => '我的卡券', 'url' => h5_url('pages/subPages/coupon/coupon'), 'page_path' => 'pages/subPages/coupon/coupon'], |
|||
['name' => '消费记录', 'url' => h5_url('pages/subPages/consumptionRecords/consumptionRecords'), 'page_path' => 'pages/subPages/consumptionRecords/consumptionRecords'], |
|||
['name' => '通讯列表', 'url' => h5_url('pages/subPages/homepage/private/private'), 'page_path' => 'pages/subPages/homepage/private/private'], |
|||
] |
|||
], |
|||
]; |
|||
#2、系统链接 - 模块链接,添加用户拥有的模块的链接信息 |
|||
if (p('rush')) { |
|||
$plugin[] = ['name' => '抢购首页', 'url' => h5_url('pages/mainPages/index/diypage?type=3'), 'page_path' => 'pages/mainPages/index/diypage?type=3']; |
|||
//分类链接 —— 抢购分类链接 |
|||
$cate['rush']['name'] = '抢购分类'; |
|||
$rushCateList = pdo_getall(PDO_NAME."rush_category",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','name'],'','sort DESC'); |
|||
foreach($rushCateList as $rushCate){ |
|||
$cate['rush']['list'][] = [ |
|||
'name' => $rushCate['name'], |
|||
'url' => h5_url('pages/subPages2/coursegoods/localindex/localindex',['type'=>3,'cate_id'=>$rushCate['id']]), |
|||
'page_path' => 'pages/subPages2/coursegoods/localindex/localindex?type=3&cate_id='.$rushCate['id'], |
|||
]; |
|||
} |
|||
} |
|||
if (p('wlfightgroup')) { |
|||
$plugin[] = ['name' => '拼团首页', 'url' => h5_url('pages/mainPages/index/diypage?type=6'), 'page_path' => 'pages/mainPages/index/diypage?type=6']; |
|||
//分类链接 —— 拼团分类链接 |
|||
$cate['wlfightgroup']['name'] = '拼团分类'; |
|||
$fightCateList = pdo_getall(PDO_NAME."fightgroup_category",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','name'],'','listorder DESC'); |
|||
foreach($fightCateList as $fightItem){ |
|||
$cate['wlfightgroup']['list'][] = [ |
|||
'name' => $fightItem['name'], |
|||
'url' => h5_url('pages/subPages2/coursegoods/localindex/localindex',['type'=>6,'cate_id'=>$fightItem['id']]), |
|||
'page_path' => 'pages/subPages2/coursegoods/localindex/localindex?type=6&cate_id='.$fightItem['id'], |
|||
]; |
|||
} |
|||
} |
|||
if (p('groupon')) { |
|||
$plugin[] = ['name' => '团购首页', 'url' => h5_url('pages/mainPages/index/diypage?type=4'), 'page_path' => 'pages/mainPages/index/diypage?type=4']; |
|||
//分类链接 —— 团购分类链接 |
|||
$cate['groupon']['name'] = '团购分类'; |
|||
$groupCateList = pdo_getall(PDO_NAME."groupon_category",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','name'],'','sort DESC'); |
|||
foreach($groupCateList as $groupItem){ |
|||
$cate['groupon']['list'][] = [ |
|||
'name' => $groupItem['name'], |
|||
'url' => h5_url('pages/subPages2/coursegoods/localindex/localindex',['type'=>4,'cate_id'=>$groupItem['id']]), |
|||
'page_path' => 'pages/subPages2/coursegoods/localindex/localindex?type=4&cate_id='.$groupItem['id'], |
|||
]; |
|||
} |
|||
} |
|||
if (p('bargain')) { |
|||
$plugin[] = ['name' => '砍价首页', 'url' => h5_url('pages/mainPages/index/diypage?type=7'), 'page_path' => 'pages/mainPages/index/diypage?type=7']; |
|||
//分类链接 —— 砍价分类链接 |
|||
$cate['bargain']['name'] = '砍价分类'; |
|||
$bargainCateList = pdo_getall(PDO_NAME."bargain_category",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','name'],'','sort DESC'); |
|||
foreach($bargainCateList as $bargainItem){ |
|||
$cate['bargain']['list'][] = [ |
|||
'name' => $bargainItem['name'], |
|||
'url' => h5_url('pages/subPages2/coursegoods/localindex/localindex',['type'=>7,'cate_id'=>$bargainItem['id']]), |
|||
'page_path' => 'pages/subPages2/coursegoods/localindex/localindex?type=7&cate_id='.$bargainItem['id'], |
|||
]; |
|||
} |
|||
} |
|||
if (p('wlcoupon')) { |
|||
$plugin[] = ['name' => '卡券首页', 'url' => h5_url('pages/mainPages/index/diypage?type=5'), 'page_path' => 'pages/mainPages/index/diypage?type=5']; |
|||
} |
|||
if (p('pocket')) { |
|||
$plugin[] = ['name' => '掌上信息', 'url' => h5_url('pages/mainPages/pocketIInformant/pocketIInformant'), 'page_path' => 'pages/mainPages/pocketIInformant/pocketIInformant']; |
|||
$plugin[] = ['name' => '我的贴子', 'url' => h5_url('pages/subPages/myPost/myPost'), 'page_path' => 'pages/subPages/myPost/myPost']; |
|||
$plugin[] = ['name' => '发布帖子', 'url' => h5_url('pages/mainPages/sendInformation/sendInformation'), 'page_path' => 'pages/mainPages/sendInformation/sendInformation']; |
|||
} |
|||
if (p('wlsign')) { |
|||
$plugin[] = ['name' => '签到页面', 'url' => h5_url('pages/subPages/signdesk/index/index'), 'page_path' => 'pages/subPages/signdesk/index/index']; |
|||
$plugin[] = ['name' => '签到记录', 'url' => h5_url('pages/subPages/signdesk/record/record'), 'page_path' => 'pages/subPages/signdesk/record/record']; |
|||
$plugin[] = ['name' => '签到排行', 'url' => h5_url('pages/subPages/signdesk/rank/rank'), 'page_path' => 'pages/subPages/signdesk/rank/rank']; |
|||
} |
|||
if (p('halfcard')) { |
|||
$plugin[] = ['name' => '购卡入口', 'url' => h5_url('pages/mainPages/memberCard/getMembership/getMembership'), 'page_path' => 'pages/mainPages/memberCard/getMembership/getMembership']; |
|||
} |
|||
if (p('consumption')) { |
|||
$plugin[] = ['name' => '积分商城首页', 'url' => h5_url('pages/subPages/integral/integralShop/integralShop'), 'page_path' => 'pages/subPages/integral/integralShop/integralShop']; |
|||
} |
|||
if (p('headline')) { |
|||
$plugin[] = ['name' => '头条列表', 'url' => h5_url('pages/mainPages/headline/index'), 'page_path' => 'pages/mainPages/headline/index']; |
|||
//分类链接 —— 头条分类链接 |
|||
$cate['headline']['name'] = '文章头条分类'; |
|||
$headCateList = pdo_getall(PDO_NAME."headline_class",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid'],'state'=>1],['id','name','head_id'],'','sort DESC'); |
|||
foreach($headCateList as $headItem){ |
|||
//判断是否存在上级菜单 生成对应的url信息 |
|||
if($headItem['head_id'] > 0) $cardUrl = "pages/mainPages/headline/index?type=13&cate_one={$headItem['head_id']}&cate_two={$headItem['id']}&title={$headItem['name']}"; |
|||
else $cardUrl = "pages/mainPages/headline/index?type=13&cate_one={$headItem['id']}&cate_two=0&title={$headItem['name']}"; |
|||
//信息赋值 |
|||
$cate['headline']['list'][] = [ |
|||
'name' => $headItem['name'] , |
|||
'url' => h5_url($cardUrl), |
|||
'page_path' => $cardUrl , |
|||
]; |
|||
} |
|||
} |
|||
if (p('citycard')) { |
|||
$plugin[] = ['name' => '名片首页', 'url' => h5_url('pages/mainPages/index/diypage?type=13'), 'page_path' => 'pages/mainPages/index/diypage?type=13']; |
|||
$plugin[] = ['name' => '名片夹', 'url' => h5_url('pages/subPages/businesscard/mycard/mycard'), 'page_path' => 'pages/subPages/businesscard/mycard/mycard']; |
|||
$plugin[] = ['name' => '我的名片', 'url' => h5_url('pages/subPages/businesscard/carddetail/renewcarddetail'), 'page_path' => 'pages/subPages/businesscard/carddetail/renewcarddetail']; |
|||
//分类链接 —— 名片分类链接 |
|||
$cate['citycard']['name'] = '名片分类'; |
|||
$cardCateList = pdo_getall(PDO_NAME."citycard_cates",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid'],'enabled'=>1],['id','name','parentid'],'','sort DESC'); |
|||
foreach($cardCateList as $cardItem){ |
|||
//判断是否存在上级菜单 生成对应的url信息 |
|||
if($cardItem['parentid'] > 0) $cardUrl = "pages/mainPages/index/diypage?type=13&cate_one={$cardItem['parentid']}&cate_two={$cardItem['id']}&title={$cardItem['name']}"; |
|||
else $cardUrl = "pages/mainPages/index/diypage?type=13&cate_one={$cardItem['id']}&cate_two=0&title={$cardItem['name']}"; |
|||
//信息赋值 |
|||
$cate['citycard']['list'][] = [ |
|||
'name' => $cardItem['name'] , |
|||
'url' => h5_url($cardUrl), |
|||
'page_path' => $cardUrl , |
|||
]; |
|||
} |
|||
} |
|||
if (p('wxapp')) { |
|||
$plugin[] = ['name' => '直播首页', 'url' => h5_url('pages/subPages/live/index'), 'page_path' => 'pages/subPages/live/index']; |
|||
} |
|||
if (file_exists(PATH_MODULE . 'L304.log')) { |
|||
$plugin[] = ['name' => '新直播首页', 'url' => h5_url('pages/subPages/live/newLive'), 'page_path' => 'pages/subPages/live/newLive']; |
|||
} |
|||
if (p('citydelivery')) { |
|||
$plugin[] = ['name' => '配送商户', 'url' => h5_url('pages/subPages2/businessCenter/businessCenter'), 'page_path' => 'pages/subPages2/businessCenter/businessCenter']; |
|||
} |
|||
if (p('redpack')) { |
|||
$plugin[] = ['name' => '红包广场', 'url' => h5_url('pages/subPages/redpacket/redsquare'), 'page_path' => 'pages/subPages/redpacket/redsquare']; |
|||
} |
|||
if (p('yellowpage')) { |
|||
$system['yellowpage'] = [ |
|||
'name' => '黄页114', |
|||
'list' => [ |
|||
['name'=>'114首页','url'=>h5_url('pages/subPages2/phoneBook/phoneBook'),'page_path' => 'pages/subPages2/phoneBook/phoneBook'], |
|||
['name'=>'黄页分类','url'=>h5_url('pages/subPages2/phoneBook/phoneClass/phoneClass'),'page_path' => 'pages/subPages2/phoneBook/phoneClass/phoneClass'], |
|||
['name'=>'黄页入驻','url'=>h5_url('pages/subPages2/phoneBook/enterForm/enterForm'),'page_path' => 'pages/subPages2/phoneBook/enterForm/enterForm'], |
|||
['name'=>'黄页收藏','url'=>h5_url('pages/subPages2/phoneBook/yellowGoods/yellowGoods'),'page_path' => 'pages/subPages2/phoneBook/yellowGoods/yellowGoods'], |
|||
['name'=>'我的黄页','url'=>h5_url('pages/subPages2/phoneBook/myGoods/myGoods'),'page_path' => 'pages/subPages2/phoneBook/myGoods/myGoods'], |
|||
] |
|||
]; |
|||
} |
|||
if (p('activity')) { |
|||
$plugin[] = [ |
|||
'name' => '活动首页' , |
|||
'url' => h5_url('pages/mainPages/index/diypage?type=14') , |
|||
'page_path' => 'pages/mainPages/index/diypage?type=14' |
|||
]; |
|||
//分类链接 —— 活动分类链接 |
|||
$cate['activity']['name'] = '活动分类'; |
|||
$activityCateList = pdo_getall(PDO_NAME."activity_category" |
|||
,['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid'],'status'=>1],['id','name'],'','sort DESC'); |
|||
foreach($activityCateList as $activityCate){ |
|||
$cate['activity']['list'][] = [ |
|||
'name' => $activityCate['name'] , |
|||
'url' => h5_url('pages/subPages2/coursegoods/localindex/localindex' , ['type' => 14 , 'cate_id' => $activityCate['id']]) , |
|||
'page_path' => 'pages/subPages2/coursegoods/localindex/localindex?type=14&cate_id=' . $activityCate['id'] , |
|||
]; |
|||
} |
|||
} |
|||
if (p('recruit')) { |
|||
//招聘主要连接 |
|||
$system['recruit'] = [ |
|||
'name' => '招聘求职', |
|||
'list' => [ |
|||
['name'=>'招聘首页','url'=>h5_url('pages/mainPages/index/diypage?type=15'),'page_path' => 'pages/mainPages/index/diypage?type=15'], |
|||
['name'=>'招聘列表','url'=>h5_url('pages/subPages2/hirePlatform/recruitmentList/recruitmentList'),'page_path' => 'pages/subPages2/hirePlatform/recruitmentList/recruitmentList'], |
|||
['name'=>'企业列表','url'=>h5_url('pages/subPages2/hirePlatform/companiesList/companiesList'),'page_path' => 'pages/subPages2/hirePlatform/companiesList/companiesList'], |
|||
['name'=>'发布招聘','url'=>h5_url('pages/subPages2/hirePlatform/postRecruitment/postRecruitment'),'page_path' => 'pages/subPages2/hirePlatform/postRecruitment/postRecruitment'], |
|||
['name'=>'我的简历','url'=>h5_url('pages/subPages2/hirePlatform/addResume/addResume'),'page_path' => 'pages/subPages2/hirePlatform/addResume/addResume'], |
|||
] |
|||
]; |
|||
//招聘行业连接 |
|||
$cate['recruit']['name'] = '招聘行业'; |
|||
$recruitCateList = pdo_getall(PDO_NAME."recruit_industry",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','title','pid'],'','sort DESC'); |
|||
foreach($recruitCateList as $recruitCate){ |
|||
if($recruitCate['pid'] > 0){ |
|||
//子行业 |
|||
$recruitData = [ |
|||
'name' => $recruitCate['title'] , |
|||
'url' => h5_url('pages/subPages2/hirePlatform/workClassList/workClassList' , ['pid'=> $recruitCate['pid'] , 'id' => $recruitCate['id']]) , |
|||
'page_path' => 'pages/subPages2/hirePlatform/workClassList/workClassList?pid=' . $recruitCate['pid']."&id=" . $recruitCate['id'], |
|||
]; |
|||
}else{ |
|||
//上级行业 |
|||
$recruitData = [ |
|||
'name' => $recruitCate['title'] , |
|||
'url' => h5_url('pages/subPages2/hirePlatform/workClassList/workClassList' , ['pid'=> $recruitCate['pid'] , 'id' => 0]) , |
|||
'page_path' => 'pages/subPages2/hirePlatform/workClassList/workClassList?pid=' . $recruitCate['pid']."&id=0", |
|||
]; |
|||
} |
|||
//信息赋值 |
|||
$cate['recruit']['list'][] = $recruitData; |
|||
} |
|||
} |
|||
if (p('vehicle')){ |
|||
$plugin[] = [ |
|||
'name' => '顺风车', |
|||
'url' => h5_url('pages/subPages2/hitchRide/index/index'), |
|||
'page_path' => 'pages/subPages2/hitchRide/index/index' |
|||
]; |
|||
} |
|||
if (uniacid_p('mobilerecharge')){ |
|||
$plugin[] = [ |
|||
'name' => '话费充值', |
|||
'url' => h5_url('pages/subPages2/voucherCenter/voucherCenter'), |
|||
'page_path' => 'pages/subPages2/voucherCenter/voucherCenter' |
|||
]; |
|||
} |
|||
$system['plugin'] = [ |
|||
'name' => '模块链接', |
|||
'list' => '' |
|||
]; |
|||
|
|||
#3、系统链接 - 分销链接 |
|||
if (p('distribution')) { |
|||
$system['distribution']['name'] = '分销链接'; |
|||
$system['distribution']['list'][] = ['name' => '分销中心', 'url' => h5_url('pages/subPages/dealer/index/index'), 'page_path' => 'pages/subPages/dealer/index/index']; |
|||
$system['distribution']['list'][] = ['name' => '客户管理', 'url' => h5_url('pages/subPages/dealer/client/client'), 'page_path' => 'pages/subPages/dealer/client/client']; |
|||
$system['distribution']['list'][] = ['name' => '推广商品', 'url' => h5_url('pages/subPages/dealer/setshop/setshop'), 'page_path' => 'pages/subPages/dealer/setshop/setshop']; |
|||
$system['distribution']['list'][] = ['name' => '提现中心', 'url' => h5_url('pages/subPages/dealer/withdraw/withdraw'), 'page_path' => 'pages/subPages/dealer/withdraw/withdraw']; |
|||
$system['distribution']['list'][] = ['name' => '提现记录', 'url' => h5_url('pages/subPages/dealer/withdraw/withdrawrecord'), 'page_path' => 'pages/subPages/dealer/withdraw/withdrawrecord']; |
|||
$system['distribution']['list'][] = ['name' => '推广订单', 'url' => h5_url('pages/subPages/dealer/gener/gener'), 'page_path' => 'pages/subPages/dealer/gener/gener']; |
|||
if(Customized::init('distributionText') > 0){ |
|||
$system['distribution']['name'] = '共享股东链接'; |
|||
$system['distribution']['list'][0]['name'] = '共享股东中心'; |
|||
} |
|||
} |
|||
#4、商户分类连接 |
|||
$shopCate = pdo_getall(PDO_NAME . "category_store", ['aid' => $_W['aid'], 'uniacid' => $_W['uniacid'],'enabled'=>1], ['id', 'name','parentid']); |
|||
$system['shop_cate']['name'] = '商户分类'; |
|||
foreach ($shopCate as $k => &$v) { |
|||
if($v['parentid'] > 0) { |
|||
$cateParams = [ |
|||
'cate_one' => $v['parentid'], |
|||
'cate_two' => $v['id'] |
|||
]; |
|||
$system['shop_cate']['list'][] = ['name' => $v['name'] , 'url' => h5_url('pages/mainPages/store/list' , $cateParams) , 'page_path' => 'pages/mainPages/store/list']; |
|||
}else{ |
|||
if(Customized::init('storecate1520') > 0){ |
|||
$cateParams = ['id' => $v['id']]; |
|||
$system['shop_cate']['list'][] = ['name' => $v['name'] , 'url' => h5_url('pages/subPages2/storeClass/storeClass' , $cateParams) , 'page_path' => 'pages/subPages2/storeClass/storeClass']; |
|||
}else{ |
|||
$cateParams = ['cate_one' => $v['id']]; |
|||
$system['shop_cate']['list'][] = ['name' => $v['name'] , 'url' => h5_url('pages/mainPages/store/list' , $cateParams) , 'page_path' => 'pages/mainPages/store/list']; |
|||
} |
|||
} |
|||
} |
|||
#4、掌上信息分类 |
|||
$pockCate = pdo_getall(PDO_NAME . "pocket_type", ['aid' => $_W['aid'], 'uniacid' => $_W['uniacid'],'status'=>1,'type'=>0] |
|||
, ['id', 'title','url'],'','sort DESC'); |
|||
$system['pock_cate']['name'] = '信息分类'; |
|||
foreach ($pockCate as $pock_k => &$pock_v) { |
|||
if ($pock_v['url']) $url = $pock_v['url']; |
|||
else $url = h5_url('pages/mainPages/econdaryClassification/econdaryClassification' , ['id' => $pock_v['id'],'title' => $pock_v['title']]); |
|||
$system['pock_cate']['list'][] = [ |
|||
'name' => $pock_v['title'] , |
|||
'url' => $url , |
|||
'page_path' => 'pages/mainPages/econdaryClassification/econdaryClassification' |
|||
]; |
|||
} |
|||
//抽奖活动链接 |
|||
if (p('draw')) { |
|||
$draw = pdo_getall(PDO_NAME . "draw" , ['aid' => $_W['aid'] , 'uniacid' => $_W['uniacid'] , 'status' => 2] , ['id' , 'title'] , '' , 'create_time DESC'); |
|||
$system['draw']['name'] = '幸运抽奖'; |
|||
foreach ($draw as $draw_k => &$draw_v) { |
|||
$url = h5_url('pages/subPages2/drawGame/drawGame' , ['id' => $draw_v['id']]); |
|||
$system['draw']['list'][] = [ |
|||
'name' => $draw_v['title'] , |
|||
'url' => $url , |
|||
'page_path' => 'pages/subPages2/drawGame/drawGame' |
|||
]; |
|||
} |
|||
} |
|||
|
|||
if(uniacid_p('luckydraw')){ |
|||
$luckydraw = pdo_getall(PDO_NAME . "luckydraw" , ['aid' => $_W['aid'] , 'uniacid' => $_W['uniacid'] , 'status' => 1] , ['id' , 'title'] , '' , 'createtime DESC'); |
|||
$system['luckydraw']['name'] = '锦鲤抽奖'; |
|||
foreach ($luckydraw as $ldraw_k => &$ldraw_v) { |
|||
$url = h5_url('pages/subPages2/lottery/lotteryIndex/lotteryIndex' , ['id' => $ldraw_v['id']]); |
|||
$system['luckydraw']['list'][] = [ |
|||
'name' => $ldraw_v['title'] , |
|||
'url' => $url , |
|||
'page_path' => 'pages/subPages2/lottery/lotteryIndex/lotteryIndex' |
|||
]; |
|||
} |
|||
} |
|||
|
|||
|
|||
//家政服务 |
|||
if (p('housekeep')){ |
|||
$plugin[] = [ |
|||
'name' => '家政服务', |
|||
'url' => h5_url('pages/mainPages/index/diypage?type=18'), |
|||
'page_path' => 'pages/mainPages/index/diypage?type=18' |
|||
]; |
|||
$system['housekeep'] = [ |
|||
'name' => '家政服务', |
|||
'list' => [ |
|||
['name'=>'家政首页','url'=>h5_url('pages/mainPages/index/diypage?type=18'),'page_path' => 'pages/mainPages/index/diypage?type=18'], |
|||
['name'=>'服务商家','url'=>h5_url('pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant'),'page_path' => 'pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant'], |
|||
['name'=>'我的需求','url'=>h5_url('pages/subPages2/homemaking/myDemand/myDemand'),'page_path' => 'pages/subPages2/homemaking/myDemand/myDemand'], |
|||
['name'=>'客户需求','url'=>h5_url('pages/subPages2/homemaking/customerDemand/customerDemand'),'page_path' => 'pages/subPages2/homemaking/customerDemand/customerDemand'], |
|||
['name'=>'我的订单','url'=>h5_url('pages/subPages2/homemaking/myorderForm/myorderForm'),'page_path' => 'pages/subPages2/homemaking/myorderForm/myorderForm'], |
|||
['name'=>'个人中心','url'=>h5_url('pages/subPages2/homemaking/homeUser/homeUser'),'page_path' => 'pages/subPages2/homemaking/homeUser/homeUser'], |
|||
['name'=>'发布需求','url'=>h5_url('pages/subPages2/homemaking/postDemand/postDemand'),'page_path' => 'pages/subPages2/homemaking/postDemand/postDemand'], |
|||
['name'=>'服务者入驻','url'=>h5_url('pages/subPages2/homemaking/serviceIn/serviceIn'),'page_path' => 'pages/subPages2/homemaking/serviceIn/serviceIn'], |
|||
] |
|||
]; |
|||
//分类链接 |
|||
$cate['housekeep']['name'] = '家政服务分类'; |
|||
$housekeepCateList = pdo_getall(PDO_NAME."housekeep_type",['uniacid'=>$_W['uniacid'],'aid'=>$_W['aid']],['id','title','onelevelid'],'','sort DESC'); |
|||
foreach($housekeepCateList as $housekeepCate) { |
|||
if ($housekeepCate['onelevelid'] > 0) { |
|||
//子行业 |
|||
$housekeepData = [ |
|||
'name' => $housekeepCate['title'], |
|||
'url' => h5_url('pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant', ['onelevelid' => $housekeepCate['onelevelid'], 'twolevelid' => $housekeepCate['id'], 'title' => $housekeepCate['title']]), |
|||
'page_path' => 'pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant?onelevelid=' . $housekeepCate['onelevelid'] . "&twolevelid=" . $housekeepCate['id'] . "&title=" . $housekeepCate['title'], |
|||
]; |
|||
} else { |
|||
//上级行业 |
|||
$housekeepData = [ |
|||
'name' => $housekeepCate['title'], |
|||
'url' => h5_url('pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant', ['onelevelid' => $housekeepCate['id'], 'twolevelid' => 0, 'title' => $housekeepCate['title']]), |
|||
'page_path' => 'pages/subPages2/homemaking/homemakingMerchant/homemakingMerchant?onelevelid=' . $housekeepCate['id'] . "&twolevelid=0&title=" . $housekeepCate['title'], |
|||
]; |
|||
} |
|||
//信息赋值 |
|||
$cate['housekeep']['list'][] = $housekeepData; |
|||
} |
|||
} |
|||
|
|||
if (p('dating')){ |
|||
$plugin[] = [ |
|||
'name' => '相亲交友', |
|||
'url' => h5_url('pages/mainPages/index/diypage?type=16'), |
|||
'page_path' => 'pages/mainPages/index/diypage?type=16' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '相亲首页', |
|||
'url' => h5_url('pages/mainPages/index/diypage?type=16'), |
|||
'page_path' => 'pages/mainPages/index/diypage?type=16' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '相亲会员', |
|||
'url' => h5_url('pages/subPages2/blindDate/member/all'), |
|||
'page_path' => 'pages/subPages2/blindDate/member/all' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '我的红娘', |
|||
'url' => h5_url('pages/subPages2/blindDate/matchmakerService'), |
|||
'page_path' => 'pages/subPages2/blindDate/matchmakerService' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '相亲会员卡', |
|||
'url' => h5_url('pages/subPages2/blindDate/member/open'), |
|||
'page_path' => 'pages/subPages2/blindDate/member/open' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '用户中心', |
|||
'url' => h5_url('pages/subPages2/blindDate/personal'), |
|||
'page_path' => 'pages/subPages2/blindDate/personal' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '交友动态', |
|||
'url' => h5_url('pages/subPages2/blindDate/dynamics/index'), |
|||
'page_path' => 'pages/subPages2/blindDate/dynamics/index' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '用户推荐', |
|||
'url' => h5_url('pages/subPages2/blindDate/recommend'), |
|||
'page_path' => 'pages/subPages2/blindDate/recommend' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '红娘服务', |
|||
'url' => h5_url('pages/subPages2/blindDate/form/matchmakerApply'), |
|||
'page_path' => 'pages/subPages2/blindDate/form/matchmakerApply' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '个人资料', |
|||
'url' => h5_url('pages/subPages2/blindDate/form/userInfo'), |
|||
'page_path' => 'pages/subPages2/blindDate/form/userInfo' |
|||
]; |
|||
$datingplugin[] = [ |
|||
'name' => '视频列表', |
|||
'url' => h5_url('pages/subPages2/blindDate/member/all',['get_type' => 1]), |
|||
'page_path' => 'pages/subPages2/blindDate/form/userInfo?get_type=1' |
|||
]; |
|||
$system['dating'] = [ |
|||
'name' => '相亲交友', |
|||
'list' => $datingplugin |
|||
]; |
|||
} |
|||
$system['plugin']['list'] = $plugin; |
|||
|
|||
|
|||
#5、判断是否只返回系统连接 |
|||
if ($state == 'system') return $system; |
|||
#6、商户链接 |
|||
$shop_pageNum = 5; |
|||
$shopWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND enabled = 1 "; |
|||
$shop = pdo_fetchall("SELECT id,storename,logo,storehours FROM " . |
|||
tablename(PDO_NAME . "merchantdata") . |
|||
" WHERE {$shopWhere} LIMIT 0,{$shop_pageNum}"); |
|||
$shop_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'merchantdata') . " WHERE {$shopWhere}"); |
|||
foreach ($shop as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/store/index', ['sid' => $v['id']]); |
|||
$v['page_path'] = 'pages/mainPages/store/list'; |
|||
$v['logo'] = tomedia($v['logo']); |
|||
$storehours = unserialize($v['storehours']); |
|||
$v['storehours'] = $storehours['startTime'] . '-' . $storehours['endTime']; |
|||
unset($v['id']); |
|||
} |
|||
$shopList['name'] = '选择店铺'; |
|||
$shopList['list'] = $shop; |
|||
#7、获取抢购商品链接列表 |
|||
$rush_pageNum = 5; |
|||
$rushWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND status IN (1,2) "; |
|||
$rush = pdo_fetchall(" SELECT id,name,thumb FROM " . tablename(PDO_NAME . "rush_activity") . " WHERE {$rushWhere} LIMIT 0,{$rush_pageNum}"); |
|||
$rush_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'rush_activity') . " WHERE {$rushWhere}"); |
|||
foreach ($rush as $k => &$v) { |
|||
$v['url'] = h5_url('pages/subPages/goods/index', ['id' => $v['id'], 'type' => 1]); |
|||
$v['page_path'] = 'pages/subPages/goods/index?type=1'; |
|||
$v['logo'] = tomedia($v['thumb']); |
|||
unset($v['id']); |
|||
} |
|||
#8、获取拼团商品链接列表 |
|||
$fightgroup_pageNum = 5; |
|||
$fightgroupWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND status IN (1,2) "; |
|||
$fightgroup = pdo_fetchall(" SELECT id,name,logo FROM " . tablename(PDO_NAME . "fightgroup_goods") . " WHERE {$fightgroupWhere} LIMIT 0,{$fightgroup_pageNum}"); |
|||
$fightgroup_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'fightgroup_goods') . " WHERE {$fightgroupWhere}"); |
|||
foreach ($fightgroup as $k => &$v) { |
|||
$v['url'] = h5_url('pages/subPages/goods/index', ['id' => $v['id'], 'type' => 3]); |
|||
$v['page_path'] = 'pages/subPages/goods/index?type=3'; |
|||
$v['logo'] = tomedia($v['logo']); |
|||
unset($v['id']); |
|||
} |
|||
#9、获取团购商品链接列表 |
|||
$groupon_pageNum = 5; |
|||
$grouponWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND status IN (1,2) "; |
|||
$groupon = pdo_fetchall(" SELECT id,name,thumb FROM " . tablename(PDO_NAME . "groupon_activity") . " WHERE {$grouponWhere} LIMIT 0,{$groupon_pageNum}"); |
|||
$groupon_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'groupon_activity') . " WHERE {$grouponWhere}"); |
|||
foreach ($groupon as $k => &$v) { |
|||
$v['url'] = h5_url('pages/subPages/goods/index', ['id' => $v['id'], 'type' => 2]); |
|||
$v['page_path'] = 'pages/subPages/goods/index?type=2'; |
|||
$v['logo'] = tomedia($v['thumb']); |
|||
unset($v['id']); |
|||
} |
|||
#10、获取优惠券链接列表 |
|||
$coupon_pageNum = 5; |
|||
$couponWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND status IN (1,2)"; |
|||
$coupon = pdo_fetchall(" SELECT id,title,logo FROM " . tablename(PDO_NAME . "couponlist") . " WHERE {$couponWhere} LIMIT 0,{$coupon_pageNum}"); |
|||
$coupon_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'couponlist') . " WHERE {$couponWhere}"); |
|||
foreach ($coupon as $k => &$v) { |
|||
$v['name'] = $v['title']; |
|||
$v['url'] = h5_url('pages/subPages/goods/index', ['id' => $v['id'], 'type' => 5]); |
|||
$v['page_path'] = 'pages/subPages/goods/index?type=5'; |
|||
$v['logo'] = tomedia($v['logo']); |
|||
unset($v['id']); |
|||
unset($v['title']); |
|||
} |
|||
#11、获取砍价商品链接列表 |
|||
$bargain_pageNum = 5; |
|||
$bargainWhere = " aid = {$_W['aid']} AND uniacid = {$_W['uniacid']} AND status IN (1,2) "; |
|||
$bargain = pdo_fetchall(" SELECT id,`name`,thumb FROM " . tablename(PDO_NAME . "bargain_activity") . " WHERE {$bargainWhere} LIMIT 0,{$bargain_pageNum}"); |
|||
$bargain_total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(PDO_NAME . 'bargain_activity') . " WHERE {$bargainWhere}"); |
|||
foreach ($bargain as $k => &$v) { |
|||
$v['url'] = h5_url('pages/subPages/goods/index', ['id' => $v['id'], 'type' => 7]); |
|||
$v['page_path'] = 'pages/subPages/goods/index?type=7'; |
|||
$v['logo'] = tomedia($v['thumb']); |
|||
unset($v['id']); |
|||
} |
|||
#12、获取自定义页面地址信息。页面类型:1=自定义页面;2=商城首页;3=抢购首页;4=团购首页;5=卡券首页;6=拼团首页;7=砍价首页 |
|||
#12-1、自定义页面 |
|||
$diyList = pdo_getall(PDO_NAME . "diypage", ['type' => 1, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($diyList) { |
|||
$pageInfo['diy']['list'] = $diyList; |
|||
$pageInfo['diy']['name'] = '自定义页面'; |
|||
foreach ($pageInfo['diy']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 1]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=1'; |
|||
} |
|||
} |
|||
#12-2、平台首页 |
|||
$homeList = pdo_getall(PDO_NAME . "diypage", ['type' => 2, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']);; |
|||
if ($homeList) { |
|||
$pageInfo['home']['name'] = '平台首页'; |
|||
$pageInfo['home']['list'] = $homeList; |
|||
foreach ($pageInfo['home']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 2]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=2'; |
|||
} |
|||
} |
|||
#12-3、抢购首页 |
|||
$rushList = pdo_getall(PDO_NAME . "diypage", ['type' => 3, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($rushList) { |
|||
$pageInfo['rush']['name'] = '抢购首页'; |
|||
$pageInfo['rush']['list'] = $rushList; |
|||
foreach ($pageInfo['rush']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 3]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=3'; |
|||
} |
|||
} |
|||
#12-4、团购首页 |
|||
$groupList = pdo_getall(PDO_NAME . "diypage", ['type' => 4, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($groupList) { |
|||
$pageInfo['groupon']['name'] = '团购首页'; |
|||
$pageInfo['groupon']['list'] = $groupList; |
|||
foreach ($pageInfo['groupon']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 4]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=4'; |
|||
} |
|||
} |
|||
#12-5、卡券首页 |
|||
$couponList = pdo_getall(PDO_NAME . "diypage", ['type' => 5, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($couponList) { |
|||
$pageInfo['coupon']['name'] = '卡券首页'; |
|||
$pageInfo['coupon']['list'] = $couponList; |
|||
foreach ($pageInfo['coupon']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 5]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=5'; |
|||
} |
|||
} |
|||
#12-6、拼团首页 |
|||
$couponList = pdo_getall(PDO_NAME . "diypage", ['type' => 6, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($couponList) { |
|||
$pageInfo['coupon']['name'] = '拼团首页'; |
|||
$pageInfo['coupon']['list'] = $couponList; |
|||
foreach ($pageInfo['coupon']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 6]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=6'; |
|||
} |
|||
} |
|||
#12-7、砍价首页 |
|||
$couponList = pdo_getall(PDO_NAME . "diypage", ['type' => 7, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'name']); |
|||
if ($couponList) { |
|||
$pageInfo['coupon']['name'] = '砍价首页'; |
|||
$pageInfo['coupon']['list'] = $couponList; |
|||
foreach ($pageInfo['coupon']['list'] as $k => &$v) { |
|||
$v['url'] = h5_url('pages/mainPages/index/diypage', ['id' => $v['id'], 'type' => 7]); |
|||
$v['page_path'] = 'pages/mainPages/index/diypage?type=7'; |
|||
} |
|||
} |
|||
#13、抢购专题链接 |
|||
$rushSpecial = pdo_getall(PDO_NAME . "rush_special", ['uniacid' => $_W['uniacid'], 'aid' => $_W['aid']], ['id', 'title']); |
|||
if ($rushSpecial) { |
|||
$rushSpecialLink = 'pages/subPages/special/rushspeci/rushspeci'; |
|||
foreach ($rushSpecial as $k => &$v) { |
|||
$v['url'] = h5_url($rushSpecialLink, ['id' => $v['id']]); |
|||
$v['page_path'] = $rushSpecialLink; |
|||
} |
|||
} |
|||
#14、信息拼装 |
|||
$data['system'] = $system; |
|||
$data['shop_total'] = $shop_total; |
|||
$data['shopList'] = $shopList; |
|||
$data['rush_total'] = $rush_total; |
|||
$data['rush'] = $rush; |
|||
$data['fightgroup_total'] = $fightgroup_total; |
|||
$data['fightgroup'] = $fightgroup; |
|||
$data['groupon_total'] = $groupon_total; |
|||
$data['groupon'] = $groupon; |
|||
$data['coupon_total'] = $coupon_total; |
|||
$data['coupon'] = $coupon; |
|||
$data['bargain_total'] = $bargain_total; |
|||
$data['bargain'] = $bargain; |
|||
$data['pageInfo'] = $pageInfo; |
|||
$data['rush_special'] = $rushSpecial; |
|||
$data['cate'] = $cate; |
|||
|
|||
|
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 需要进行转换的路径信息 |
|||
* Author: zzw |
|||
* Date: 2020/4/15 14:03 |
|||
* @return array |
|||
*/ |
|||
public static function getTransformationLink(){ |
|||
return [ |
|||
'dashboard/home/index' => 'pages/mainPages/index/index' , //首页 |
|||
'store/supervise/information' => 'pages/mainPages/Settled/Settled' , //商家入驻 |
|||
'store/storeManage/index' => 'pages/subPages/dealer/myStoreDetails/myStoreDetails' , //商家中心 |
|||
'member/user/index' => 'pages/mainPages/userCenter/userCenter' , //个人中心 |
|||
'store/merchant/newindex' => 'pages/mainPages/index/diypage?type=8' , //好店 |
|||
'diypage/diyhome/home' => 'pages/mainPages/index/diypage?type=1' , //自定义页面 |
|||
'rush/home/index' => 'pages/mainPages/index/diypage?type=3' , //抢购首页 |
|||
'groupon/grouponapp/grouponlist' => 'pages/mainPages/index/diypage?type=4' , //团购首页 |
|||
'wlcoupon/coupon_app/couponslist' => 'pages/mainPages/index/diypage?type=5' , //卡券首页 |
|||
'wlfightgroup/fightapp/fightindex' => 'pages/mainPages/index/diypage?type=6' , //拼团首页 |
|||
'bargain/bargain_app/bargainlist' => 'pages/mainPages/index/diypage?type=7' , //砍价首页 |
|||
'order/userorder/orderlist' => 'pages/subPages/orderList/orderList' , //我的订单列表 |
|||
'distribution/disappbase/index' => 'pages/subPages/dealer/index/index' , //分销中心 |
|||
'distribution/disappbase/applyindex' => 'pages/subPages/dealer/apply/apply' , //申请分销 |
|||
'rush/home/detail' => 'pages/subPages/goods/index' , //商品详情页(抢购) |
|||
'groupon/grouponapp/groupondetail' => 'pages/subPages/goods/index' , //商品详情页(团购) |
|||
'wlfightgroup/fightapp/goodsdetail' => 'pages/subPages/goods/index' , //商品详情页(拼团) |
|||
'bargain/bargain_app/bargaindetail' => 'pages/subPages/goods/index' , //商品详情页(砍价) |
|||
'wlcoupon/coupon_app/couponsdetail' => 'pages/subPages/goods/index' , //商品详情页(卡券) |
|||
'pocket/pocket/index' => 'pages/mainPages/pocketIInformant/pocketIInformant' , //掌上信息首页 |
|||
'halfcard/halfcard_app/userhalfcard' => 'pages/mainPages/memberCard/memberCard' , //一卡通首页 |
|||
'halfcard/halfcardopen/open' => 'pages/mainPages/memberCard/getMembership/getMembership' , //一卡通开卡入口 |
|||
'pocket/pocket/myinform' => 'pages/subPages/myPost/myPost' , //我的帖子 |
|||
'wlcoupon/coupon_app/couponList' => 'pages/subPages/coupon/coupon' , //我的卡券 |
|||
'wlsign/signapp/signindex' => 'pages/subPages/signdesk/index/index' , //签到页面 |
|||
'wlsign/signapp/signrecord' => 'pages/subPages/signdesk/record/record' , //签到记录 |
|||
'wlsign/signapp/signrank' => 'pages/subPages/signdesk/rank/rank' , //签到排行 |
|||
'store/merchant/detail' => 'pages/mainPages/store/index' , //商户详情 |
|||
'order/userorder/payover' => 'pages/mainPages/paySuccess/paySuccess' , //支付成功 |
|||
'wlfightgroup/fightapp/expressorder' => 'pages/subPages/orderList/orderDetails/orderDetails' , //订单详情(拼团) |
|||
'distribution/disappbase/apply' => 'pages/subPages/dealer/withdraw/withdrawrecord' , //分销商提现记录(详情) |
|||
'distribution/disappbase/lowpeople' => 'pages/subPages/dealer/client/client' , //分销商客户信息 |
|||
'distribution/disappbase/topayorder' => 'pages/mainPages/payment/payment' , //订单支付页面 |
|||
'consumption/goods/recordlist' => 'pages/subPages/orderList/orderList' , //积分商城兑换记录 转为订单列表 |
|||
'area/region/index#/pages/mainPages/headline/index' => 'pages/mainPages/headline/index' ,//头条 |
|||
'pages/mainPages/goods/index' => 'pages/subPages/goods/index' ,//商品链接 主包到分包 |
|||
'pages/mainPages/myPost/myPost' => 'pages/subPages/myPost/myPost' ,//我的帖子 主包到分包 |
|||
]; |
|||
} |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,231 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
use EasyWeChat\Factory; |
|||
|
|||
/** |
|||
* Comment: 登录模型 |
|||
* Author: zzw |
|||
* Class Login |
|||
*/ |
|||
class Login { |
|||
# 'loginSource1Mode2'=公众号微信登录; |
|||
# 'loginSource2Mode1'=H5账号密码登录; |
|||
# 'loginSource3Mode2'=小程序微信登录; |
|||
|
|||
/** |
|||
* Comment: 公众号微信登录 —— 等待对接 |
|||
* Author: zzw |
|||
* Date: 2019/10/22 11:32 |
|||
* @param $data |
|||
* @return mixed |
|||
*/ |
|||
public function loginSource1Mode2($data) { |
|||
global $_W; |
|||
// $data['vue_url'] = 'https://citydev.weliam.com.cn/addons/weliam_smartcity/h5/#/pages/mainPages/userCenter/userCenter?i=26'; |
|||
#1、获取基本配置信息 |
|||
$set = Util::object_array($_W['account']); |
|||
if ($data['request'] == 'get') { |
|||
#2、生成返回地址并且进行对应的编码 |
|||
$vueUrl = urlencode($data['vue_url']);//将返回地址进行编码 |
|||
$backUrl = urlencode($_W['siteroot'] . "addons/".MODULE_NAME."/core/common/uniapp.php?i=" |
|||
. $_W['uniacid'] . "&areaid={$data['areaid']}&p=member&do=login&source=1&mode=2&back_url={$vueUrl}"); |
|||
#2、发送获取code的链接请求 |
|||
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$set['key']}&redirect_uri={$backUrl}&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"; |
|||
|
|||
header("Location:" . $url); |
|||
exit; |
|||
} |
|||
#3、获取返回的信息 进行用户登录授权的操作 |
|||
$code = $data['code']; |
|||
#4、判断当前code是否已被使用 已被使用则从新获取code |
|||
if (Cache::getCache($code, $code)) { |
|||
$data['request'] = 'get'; |
|||
self::loginSource1Mode2($data); |
|||
die; |
|||
} |
|||
Cache::setCache($code, $code, $code);//储存code信息 |
|||
#5、获取用户token信息 |
|||
$tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token"; |
|||
$tokenParams = [ |
|||
'appid' => $set['key'], |
|||
'secret' => $set['secret'], |
|||
'code' => $code, |
|||
'grant_type' => 'authorization_code', |
|||
]; |
|||
$tokenInfo = curlPostRequest($tokenUrl, $tokenParams); |
|||
#6、获取用户信息 |
|||
$userUrl = "https://api.weixin.qq.com/sns/userinfo"; |
|||
$userParams = [ |
|||
'access_token' => $tokenInfo['access_token'], |
|||
'openid' => $tokenInfo['openid'], |
|||
'lang' => 'zh_CN', |
|||
]; |
|||
$userInfo = curlPostRequest($userUrl, $userParams); |
|||
|
|||
return $userInfo; |
|||
} |
|||
/** |
|||
* Comment: H5账号密码登录 —— 等待对接 |
|||
* Author: zzw |
|||
* Date: 2019/10/22 9:38 |
|||
* @param $data |
|||
*/ |
|||
public function loginSource2Mode1($data) { |
|||
global $_W; |
|||
#1、参数获取 |
|||
$type = $data['type'] ? $data['type'] : 1;//1=账号密码登录 2=短信验证码登录 |
|||
$phone = $data['phone'];//手机号 |
|||
$pwd = $data['password'];// 登录密码/短信验证码 |
|||
$backUrl = urldecode($data['backurl']); |
|||
if (!$phone) Commons::sRenderError('请输入登录账号'); |
|||
if (!$pwd) Commons::sRenderError($type == 1 ? '请输入密码' : '请输入验证码'); |
|||
#2、根据登录方式进行判断是否登录成功 |
|||
$member = pdo_get(PDO_NAME . "member", ['mobile' => $phone], ['password', 'id', 'salt', 'tokey', 'openid']); |
|||
if (!$member) Commons::sRenderError('账号不存在,请先注册!'); |
|||
if ($type == 1) { |
|||
//账号密码登录 判断密码是否正确 |
|||
if ($member['password'] != md5($pwd . $member['salt'])) Commons::sRenderError('密码错误!'); |
|||
} else { |
|||
//短信验证码登录 判断验证码是否输入正确 |
|||
$pin_info = pdo_get('wlmerchant_pincode',array('mobile' => $phone)); |
|||
if(empty($pin_info)){ |
|||
$this->renderError('验证码错误'); |
|||
} |
|||
if($pin_info['time'] < time() - 300){ |
|||
$this->renderError('验证码已过期,请重新获取',array('code'=>1)); |
|||
} |
|||
if ($pwd != $pin_info['code']) Commons::sRenderError('验证码错误!'); |
|||
} |
|||
#3、密码输出正确 成功登录 |
|||
$userInfo = [ |
|||
'mobile' => $phone, |
|||
'pwd' => $pwd, |
|||
'openid' => $member['openid'] ? $member['openid'] : $_W['wlmember']['openid'], |
|||
'tokey' => $member['tokey'] ? $member['tokey'] : $_W['wlmember']['tokey'], |
|||
]; |
|||
wl_setcookie('usersign', $userInfo, 3600 * 24 * 30); |
|||
wl_setcookie('user_token', $userInfo['tokey'], 3600 * 24 * 30); |
|||
wl_setcookie('exitlogin_code', [], 100); |
|||
#3、登录成功 返回跳转地址 |
|||
$link = $backUrl ? $backUrl : ''; |
|||
|
|||
|
|||
Commons::sRenderSuccess('登录成功', ['back_url' => $link, 'token' => $userInfo['tokey']]); |
|||
} |
|||
/** |
|||
* Comment: 小程序微信登录 |
|||
* Author: zzw |
|||
* Date: 2019/10/29 16:33 |
|||
* @param $data |
|||
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|||
*/ |
|||
static function loginSource3Mode2($data) { |
|||
global $_W; |
|||
if (!$data['code']) { |
|||
return error(1, '错误的code信息!'); |
|||
} |
|||
#1、获取微信小程序设置项 并且配置基本信息 |
|||
if (is_array($_W['wlsetting']['wxapp_config']) && count($_W['wlsetting']['wxapp_config']) > 0) { |
|||
$set = $_W['wlsetting']['wxapp_config']; |
|||
} else { |
|||
$set = Setting::wlsetting_read('wxapp_config'); |
|||
} |
|||
$config = [ |
|||
'app_id' => $set['appid'], |
|||
'secret' => $set['secret'], |
|||
]; |
|||
#3、请求获取用户信息 |
|||
try { |
|||
$app = Factory::miniProgram($config); |
|||
$userInfo = $app->auth->session($data['code']); |
|||
return $userInfo; |
|||
} catch (Exception $e) { |
|||
//错误抛出 |
|||
return error(1, $e->getMessage()); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
public static function generateToken($token,$type = ''){ |
|||
//200:成功 登陆成功/访问成功 |
|||
//401:未授权 重新登陆 |
|||
//205:刷新token 访问成功,但是刷新秘钥 |
|||
|
|||
|
|||
#token 为用户储存在数据中的token 唯一不变 |
|||
#secretKey 为用户登陆秘钥,需要返回给移动端 |
|||
|
|||
|
|||
|
|||
#1、基本信息设置 |
|||
$keyName = 'jwt_info'; |
|||
if($type === 'login'){ |
|||
$secretKey = self::createToken($token); |
|||
if($secretKey['errno'] == 401){ |
|||
return error(401); |
|||
} |
|||
|
|||
return error(200,$secretKey); |
|||
}else{ |
|||
#1、访问请求操作 获取秘钥信息 根据状态返回信息 |
|||
$loginDescInfo = pdo_get('wlmerchant_login',array('secret_key' => $token)); |
|||
//授权信息不存在 请重新登陆 |
|||
if(is_array($loginDescInfo)){ |
|||
if(empty($loginDescInfo['token'])){ |
|||
file_put_contents(PATH_DATA . "login_error.log", var_export($loginDescInfo, true) . PHP_EOL, FILE_APPEND); |
|||
return error(401); |
|||
} |
|||
if($loginDescInfo['refresh_time'] > time()){ |
|||
//未到刷新信息 访问请求有效 继续下一步操作 |
|||
return error(200,$loginDescInfo['token']); |
|||
}else if($loginDescInfo['refresh_time'] <= time() && $loginDescInfo['end_time'] > time()){ |
|||
//超过刷新时间 但是未过期 刷新访问秘钥 然后返回新的秘钥 |
|||
$secretKey = self::createToken($loginDescInfo['token']); |
|||
if($secretKey['errno'] == 401){ |
|||
file_put_contents(PATH_DATA . "login_error.log", var_export('刷新失败', true) . PHP_EOL, FILE_APPEND); |
|||
return error(401); |
|||
} |
|||
return error(205,$secretKey); |
|||
}else{ |
|||
//其他情况 统一视为登陆过期 请重新登陆 |
|||
file_put_contents(PATH_DATA . "login_error.log", var_export('其他情况', true) . PHP_EOL, FILE_APPEND); |
|||
|
|||
return error(401); |
|||
} |
|||
} |
|||
} |
|||
file_put_contents(PATH_DATA . "login_error.log", var_export('更多其他情况', true) . PHP_EOL, FILE_APPEND); |
|||
return error(401); |
|||
} |
|||
|
|||
|
|||
protected static function createToken($token){ |
|||
//登陆操作 生成登陆秘钥 |
|||
if(empty($token)){ |
|||
return error(401); |
|||
} |
|||
$data = [ |
|||
'token' => $token ,//用户token 唯一 |
|||
'secret_key' => md5($token . time()) ,//用户秘钥 |
|||
'refresh_time' => time() + (86400 * 30) ,//秘钥刷新时间 |
|||
'end_time' => time() + (86400 * 60) ,//秘钥过期时间 |
|||
]; |
|||
pdo_delete('wlmerchant_login',array('token'=>$token)); |
|||
pdo_insert(PDO_NAME . 'login', $data); |
|||
return $data['secret_key']; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,177 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Logistics { |
|||
/** |
|||
* Comment: 通过物流id获取物流信息 |
|||
* Author: zzw |
|||
* Date: 2019/10/8 14:31 |
|||
* @param $id int 物流信息id(express表的id) |
|||
* @return mixed |
|||
*/ |
|||
public static function orderLogisticsInfo($id){ |
|||
#1、获取设置信息 |
|||
$set = Setting::wlsetting_read('api')['logistics']; |
|||
if(!$set) Commons::sRenderError('平台暂未开启物流查询'); |
|||
#1、根据物流类型调用物流信息查询方法 |
|||
switch ($set['type']){ |
|||
case 1; |
|||
$res = self::logisticsSelectFunction_1($set,$id); |
|||
if($res['EBusinessID'] == 1630990){ |
|||
//报错 使用付费版本再次获取 |
|||
$res = self::logisticsSelectFunction_1($set,$id,8001); |
|||
} |
|||
break;//快递鸟 |
|||
case 2;break;//菜鸟裹裹 |
|||
case 3;break;//快递100 |
|||
default:Commons::sRenderError('平台暂未开启物流查询');break; |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
/** |
|||
* Comment: 物流信息查询方法一(快递鸟) |
|||
* Author: zzw |
|||
* Date: 2019/10/8 16:15 |
|||
* @param $set array 设置信息 |
|||
* @param $id int 物流id |
|||
* @param int $requestType 1002=免费版本;8001=付费版本 |
|||
* @return mixed |
|||
*/ |
|||
protected static function logisticsSelectFunction_1($set,$id,$requestType = 1002){ |
|||
#1、获取设置信息 |
|||
$userId = trim($set['id']);//电商ID |
|||
$AppKey = trim($set['app_key']);//电商加密私钥 |
|||
$ReqURL = 'http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';//请求url |
|||
#2、获取物流信息 |
|||
$info = pdo_get(PDO_NAME."express",['id'=>$id],['expressname','expresssn','tel']) OR Commons::sRenderError('暂无物流信息'); |
|||
$logisticsInfo = self::codeComparisonTable($info['expressname'],'alias'); |
|||
#3、生成请求内容 |
|||
$requestDataParams = [ |
|||
'OrderCode' => '' ,//订单编号 |
|||
'ShipperCode' => trim($logisticsInfo['code']) ,//快递公司编码 |
|||
'LogisticCode' => trim($info['expresssn']) ,//物流单号 |
|||
]; |
|||
if(trim($logisticsInfo['code']) == 'SF') $requestDataParams['CustomerName'] = substr($info['tel'],-4); |
|||
if(trim($logisticsInfo['code']) == 'JD') $requestDataParams['CustomerName'] = trim($set['jd_code']); |
|||
$requestData = json_encode($requestDataParams); |
|||
$data = [ |
|||
'EBusinessID' => $userId, |
|||
'RequestType' => $requestType,//1002=免费版本;8001=付费版本 |
|||
'RequestData' => urlencode($requestData) , |
|||
'DataType' => '2', |
|||
]; |
|||
#4、生成请求签名 |
|||
$data['DataSign'] = urlencode(base64_encode(md5($requestData.$AppKey))); |
|||
#4、生成请求header头部信息 |
|||
$temps = array(); |
|||
foreach ($data as $key => $value) { |
|||
$temps[] = sprintf('%s=%s', $key, $value); |
|||
} |
|||
$post_data = implode('&', $temps); |
|||
$url_info = parse_url($ReqURL); |
|||
if(empty($url_info['port'])) { |
|||
$url_info['port']=80; |
|||
} |
|||
$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n"; |
|||
$httpheader.= "Host:" . $url_info['host'] . "\r\n"; |
|||
$httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n"; |
|||
$httpheader.= "Content-Length:" . strlen($post_data) . "\r\n"; |
|||
$httpheader.= "Connection:close\r\n\r\n"; |
|||
$httpheader.= $post_data; |
|||
#4、请求获取物流信息 |
|||
return curlPostRequest($ReqURL,$data,$httpheader); |
|||
} |
|||
/** |
|||
* Comment: 通过类型匹配物流公司信息 |
|||
* Author: zzw |
|||
* Date: 2019/10/8 16:56 |
|||
* @param $name string 物流公司配置名称(name=匹配名称,alias=匹配别名,code=匹配编码) |
|||
* @param $type int 匹配类型 |
|||
* @param $getArray bool 是否返回所有物流公司信息数组 |
|||
* @return array |
|||
*/ |
|||
public static function codeComparisonTable($name = '',$type = 0,$getArray = false){ |
|||
#1、生成匹配项数组 |
|||
$data = [ |
|||
[ 'name' => '顺丰' , 'alias' => 'shunfeng' , 'code' => 'SF' ] , |
|||
[ 'name' => '百世快递' , 'alias' => 'baishikuaidi' , 'code' => 'HTKY' ] , |
|||
[ 'name' => '中通快递' , 'alias' => 'zhongtong' , 'code' => 'ZTO' ] , |
|||
[ 'name' => '申通快递' , 'alias' => 'shentong' , 'code' => 'STO' ] , |
|||
[ 'name' => '圆通速递' , 'alias' => 'yuantong' , 'code' => 'YTO' ] , |
|||
[ 'name' => '韵达速递' , 'alias' => 'yundasd' , 'code' => 'YD' ] , |
|||
[ 'name' => '邮政快递包裹' , 'alias' => 'youzhengguonei' , 'code' => 'YZPY' ] , |
|||
[ 'name' => 'EMS' , 'alias' => 'ems' , 'code' => 'EMS' ] , |
|||
[ 'name' => '天天快递' , 'alias' => 'tiantian' , 'code' => 'HHTT' ] , |
|||
[ 'name' => '京东快递' , 'alias' => 'jd' , 'code' => 'JD' ] , |
|||
[ 'name' => '优速快递' , 'alias' => 'youshuwuliu' , 'code' => 'UC' ] , |
|||
[ 'name' => '德邦快递' , 'alias' => 'debangwuliu' , 'code' => 'DBL' ] , |
|||
[ 'name' => '极兔快递' , 'alias' => 'JTSD' , 'code' => 'JTSD' ] , |
|||
[ 'name' => '宅急送' , 'alias' => 'zhaijisong' , 'code' => 'ZJS' ] , |
|||
[ 'name' => 'aae全球专递' , 'alias' => 'aae' , 'code' => 'AAE' ] , |
|||
[ 'name' => '安捷快递' , 'alias' => 'anjie' , 'code' => 'AJ' ] , |
|||
[ 'name' => 'bht' , 'alias' => 'bht' , 'code' => 'BHT' ] , |
|||
[ 'name' => '百福东方国际物流' , 'alias' => 'baifudongfang' , 'code' => 'BFDF' ] , |
|||
[ 'name' => '中国东方(COE)' , 'alias' => 'coe' , 'code' => 'COE' ] , |
|||
[ 'name' => '中国东方(COE)' , 'alias' => 'coe' , 'code' => 'COE' ] , |
|||
[ 'name' => '大田物流' , 'alias' => 'datianwuliu' , 'code' => 'DTWL' ] , |
|||
[ 'name' => 'dhl' , 'alias' => 'dhl' , 'code' => 'DHL' ] , |
|||
[ 'name' => 'dpex' , 'alias' => 'dpex' , 'code' => 'DPEX' ] , |
|||
[ 'name' => 'd速快递' , 'alias' => 'dsukuaidi' , 'code' => 'DSWL' ] , |
|||
[ 'name' => '递四方' , 'alias' => 'disifang' , 'code' => 'D4PX' ] , |
|||
[ 'name' => 'fedex(国外)' , 'alias' => 'fedex' , 'code' => 'FEDEX_GJ' ] , |
|||
[ 'name' => 'fedex(国外)' , 'alias' => 'fedex' , 'code' => 'FEDEX_GJ' ] , |
|||
[ 'name' => '飞康达物流' , 'alias' => 'feikangda' , 'code' => 'FKD' ] , |
|||
[ 'name' => '广东邮政物流' , 'alias' => 'guangdongyouzhengwuliu' , 'code' => 'GDEMS' ] , |
|||
[ 'name' => '共速达' , 'alias' => 'gongsuda' , 'code' => 'GSD' ] , |
|||
[ 'name' => '恒路物流' , 'alias' => 'hengluwuliu' , 'code' => 'HLWL' ] , |
|||
[ 'name' => '华夏龙物流' , 'alias' => 'huaxialongwuliu' , 'code' => 'HXLWL' ] , |
|||
[ 'name' => '佳怡物流' , 'alias' => 'jiayiwuliu' , 'code' => 'JYWL' ] , |
|||
[ 'name' => '京广速递' , 'alias' => 'jinguangsudikuaijian' , 'code' => 'JGSD' ] , |
|||
[ 'name' => '急先达' , 'alias' => 'jixianda' , 'code' => 'JXD' ] , |
|||
[ 'name' => '佳吉物流' , 'alias' => 'jjwl' , 'code' => 'CNEX' ] , |
|||
[ 'name' => '加运美物流' , 'alias' => 'jymwl' , 'code' => 'JYM' ] , |
|||
[ 'name' => '晋越快递' , 'alias' => 'jykd' , 'code' => 'JYKD' ] , |
|||
[ 'name' => '快捷速递' , 'alias' => 'kuaijiesudi' , 'code' => 'DJKJWL' ] , |
|||
[ 'name' => '联邦快递(国内)' , 'alias' => 'lianb' , 'code' => 'FEDEX' ] , |
|||
[ 'name' => '联邦快递(国内)' , 'alias' => 'lianb' , 'code' => 'FEDEX' ] , |
|||
[ 'name' => '联昊通物流' , 'alias' => 'lianhaowuliu' , 'code' => 'LHT' ] , |
|||
[ 'name' => '龙邦物流' , 'alias' => 'longbanwuliu' , 'code' => 'LB' ] , |
|||
[ 'name' => '立即送' , 'alias' => 'lijisong' , 'code' => 'LJSKD' ] , |
|||
[ 'name' => '民航快递' , 'alias' => 'minghangkuaidi' , 'code' => 'MHKD' ] , |
|||
[ 'name' => '门对门' , 'alias' => 'menduimen' , 'code' => 'MDM' ] , |
|||
[ 'name' => 'OCS' , 'alias' => 'ocs' , 'code' => 'OCS' ] , |
|||
[ 'name' => '全晨快递' , 'alias' => 'quanchenkuaidi' , 'code' => 'QCKD' ] , |
|||
[ 'name' => '全日通快递' , 'alias' => 'quanritongkuaidi' , 'code' => 'QRT' ] , |
|||
[ 'name' => '全一快递' , 'alias' => 'quanyikuaidi' , 'code' => 'UAPEX' ] , |
|||
[ 'name' => '如风达' , 'alias' => 'rufengda' , 'code' => 'RFD' ] , |
|||
[ 'name' => '速尔物流' , 'alias' => 'sue' , 'code' => 'SURE' ] , |
|||
[ 'name' => '盛丰物流' , 'alias' => 'shengfeng' , 'code' => 'SFWL' ] , |
|||
[ 'name' => '赛澳递' , 'alias' => 'saiaodi' , 'code' => 'SAD' ] , |
|||
[ 'name' => '天地华宇' , 'alias' => 'tiandihuayu' , 'code' => 'HOAU' ] , |
|||
[ 'name' => 'tnt' , 'alias' => 'tnt' , 'code' => 'TNT' ] , |
|||
[ 'name' => 'ups' , 'alias' => 'ups' , 'code' => 'UPS' ] , |
|||
[ 'name' => '万家物流' , 'alias' => 'wanjiawuliu' , 'code' => 'WJWL' ] , |
|||
[ 'name' => '万象物流' , 'alias' => 'wxwl' , 'code' => 'WXWL' ] , |
|||
[ 'name' => '信丰物流' , 'alias' => 'xinfengwuliu' , 'code' => 'XFEX' ] , |
|||
[ 'name' => '亚风速递' , 'alias' => 'yafengsudi' , 'code' => 'YFSD' ] , |
|||
[ 'name' => '邮政国际包裹挂号信' , 'alias' => 'youzhengguoji' , 'code' => 'GJYZ' ] , |
|||
[ 'name' => '远成物流' , 'alias' => 'yuanchengwuliu' , 'code' => 'YCWL' ] , |
|||
[ 'name' => '运通快递' , 'alias' => 'yuntongkuaidi' , 'code' => 'YTKD' ] , |
|||
[ 'name' => '源安达' , 'alias' => 'yad' , 'code' => 'YADEX' ] , |
|||
[ 'name' => '中铁快运' , 'alias' => 'zhongtiekuaiyun' , 'code' => 'ZTWL' ] , |
|||
[ 'name' => '中邮物流' , 'alias' => 'zhongyouwuliu' , 'code' => 'ZYKD' ] , |
|||
[ 'name' => '芝麻开门' , 'alias' => 'zhimakaimen' , 'code' => 'ZMKM' ] , |
|||
[ 'name' => '韵达快运' , 'alias' => 'yunda' , 'code' => 'YDKY' ] , |
|||
[ 'name' => '其他快递' , 'alias' => '' , 'code' => '' ] , |
|||
]; |
|||
if($getArray) return $data;//返回所有物流公司信息数组 |
|||
#2、根据匹配类型进行数组转码,将对应类型的键值转为键名 |
|||
$key = array_column($data,trim($type)); |
|||
$newData = array_combine($key,$data); |
|||
#2、返回匹配内容 |
|||
return $newData[$name]; |
|||
} |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,649 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
class Member { |
|||
|
|||
/** |
|||
* 根据openid获取用户信息 |
|||
* @param $openid |
|||
* @return array |
|||
*/ |
|||
static function wl_fans_info($openid) { |
|||
load()->model('mc'); |
|||
$fansinfo = mc_fansinfo($openid); |
|||
if (empty($fansinfo)) { |
|||
$fansinfo = mc_init_fans_info($openid, true); |
|||
} |
|||
$userinfo = array( |
|||
'uid' => $fansinfo['uid'], |
|||
'openid' => $fansinfo['openid'], |
|||
'nickname' => $fansinfo['nickname'], |
|||
'avatar' => $fansinfo['avatar'], |
|||
'unionid' => $fansinfo['unionid'] |
|||
); |
|||
return $userinfo; |
|||
} |
|||
|
|||
/** |
|||
* 获取用户信息 |
|||
* @param $mcinfo 用户id|用户openid|条件 |
|||
* @param array $fields 字段,留空返回全部信息 |
|||
* @param bool $credit 是否需要返回微擎用户积分余额 |
|||
* @return bool |
|||
*/ |
|||
static function wl_member_get($mcinfo, $fields = [], $credit = true) { |
|||
global $_W; |
|||
if (is_array($mcinfo)) { |
|||
//$where = $mcinfo; |
|||
$member = pdo_get(PDO_NAME . 'member', array_merge($mcinfo, array('uniacid' => $_W['uniacid'])), $fields); |
|||
} else { |
|||
$field = is_array($fields) && count($fields) > 0 ? implode(',',$fields) : '*'; |
|||
$member = pdo_fetch("SELECT {$field} FROM ".tablename(PDO_NAME."member") |
|||
." WHERE id = {$mcinfo} OR openid = '{$mcinfo}' "); |
|||
//$where = intval($mcinfo) ? ['id' => $mcinfo] : ['openid' => $mcinfo]; |
|||
} |
|||
//$member = pdo_get(PDO_NAME . 'member', array_merge($where, array('uniacid' => $_W['uniacid'])), $fields); |
|||
// if(!empty($member['openid']) && $_W['source'] == 1){ |
|||
// $newinfo = self::wl_fans_info($member['openid']); |
|||
// $member['avatar'] = $newinfo['avatar']; |
|||
// $member['nickname'] = $newinfo['nickname']; |
|||
// pdo_update(PDO_NAME . 'member',array('avatar' => $newinfo['avatar'],'nickname' => $newinfo['nickname']),array('openid' => $member['openid'])); |
|||
// } |
|||
if (!empty($member['uid']) && $credit) { |
|||
load()->model('mc'); |
|||
$credits = pdo_get('mc_members', array('uid' => $member['uid']), array('credit1', 'credit2')); |
|||
$member['credit1'] = $credits['credit1']; |
|||
$member['credit2'] = $credits['credit2']; |
|||
} |
|||
if (!empty($member['nickname']) && !empty($member['encodename'])) { |
|||
$member['nickname'] = base64_decode($member['encodename']); |
|||
} |
|||
return $member; |
|||
} |
|||
|
|||
/** |
|||
* 创建新用户 |
|||
* @param $userinfo 用户信息 |
|||
* @param string $channel 渠道wechat(微信公众号)wxapp(微信小程序)webapp(打包APP)mobile(H5手机号) |
|||
* @return array|bool |
|||
*/ |
|||
static function wl_member_create($userinfo, $channel = 'wechat') { |
|||
global $_W; |
|||
$userinfo['encodename'] = base64_encode($userinfo['nickname']); |
|||
$channels = ['wechat' => 'openid', 'wxapp' => 'wechat_openid', 'webapp' => 'webapp_openid', 'mobile' => 'mobile']; |
|||
if (!in_array($channel, array_keys($channels))) { |
|||
return error(1, '渠道错误,请检查后重试'); |
|||
} |
|||
|
|||
$uidstr = $channels[$channel]; |
|||
if (empty($userinfo[$uidstr])) { |
|||
return error(1, '缺少用户标识,请检查后重试'); |
|||
} |
|||
$member = self::wl_member_get([$uidstr => $userinfo[$uidstr]]); |
|||
if (empty($member) && !empty($userinfo['unionid'])) { |
|||
$member = self::wl_member_get(['unionid' => $userinfo['unionid']]); |
|||
} |
|||
|
|||
$newinfo = []; |
|||
$fields = self::wl_member_update_fields(); |
|||
foreach ($fields as $field) { |
|||
if (!empty($userinfo[$field])) { |
|||
$newinfo[$field] = $userinfo[$field]; |
|||
} |
|||
} |
|||
|
|||
if (empty($member)) { |
|||
$newinfo['avatar'] = $newinfo['avatar'] ? str_replace('132132', '132', $newinfo['avatar']) : './addons/'.MODULE_NAME.'/h5/resource/image/default_avatar.png'; |
|||
$member = array( |
|||
'uniacid' => $_W['uniacid'], |
|||
'tokey' => strtoupper(MD5(sha1(time() . random(12)))), |
|||
'createtime' => time(), |
|||
'dotime' => time() |
|||
); |
|||
$member = array_merge($member, $newinfo); |
|||
if (!empty($member['openid'])) { |
|||
$member['uid'] = mc_openid2uid($member['openid']); |
|||
} |
|||
if(empty($member['uid'])){ |
|||
$member['uid'] = self::createUserInfo($member['nickname']); |
|||
} |
|||
pdo_insert(PDO_NAME . 'member', $member); |
|||
$member['id'] = pdo_insertid(); |
|||
} else { |
|||
//判断是否存在uid 不存在则添加uid |
|||
$uid = pdo_getcolumn(PDO_NAME."member",['id'=>$member['id']],'uid'); |
|||
if($uid <= 0){ |
|||
$newinfo['uid'] = self::createUserInfo($member['nickname']); |
|||
} |
|||
$member = self::wl_member_update($newinfo, $member['id']); |
|||
} |
|||
|
|||
return $member; |
|||
} |
|||
|
|||
/** |
|||
* 更新用户信息 |
|||
* @param $userinfo 用户信息 |
|||
* @param $mid 用户ID |
|||
* @return array|bool |
|||
*/ |
|||
static function wl_member_update($userinfo, $mid) { |
|||
global $_W; |
|||
load()->model('mc'); |
|||
$member = self::wl_member_get($mid, [], false); |
|||
if (empty($member)) { |
|||
return error(1, '用户不存在,请检查后重试'); |
|||
} |
|||
if(empty($userinfo['uid'])){ |
|||
$userinfo['uid'] = $member['uid']; |
|||
} |
|||
$upgrade = array('dotime' => time()); |
|||
//同步用户积分信息 |
|||
$uid = 0; |
|||
if (!empty($member['openid'])) { |
|||
$uid = mc_openid2uid($member['openid']); |
|||
} |
|||
if (!empty($uid)) { |
|||
if($userinfo['uid'] != $uid){ |
|||
$creditarray = pdo_get('mc_members',array('uid'=>$userinfo['uid']),array('credit1','credit2')); |
|||
$member['credit1'] = $creditarray['credit1']; |
|||
$member['credit2'] = $creditarray['credit2']; |
|||
$zoreres = pdo_update('mc_members',array('credit1' => 0,'credit2' => 0),array('uid' => $userinfo['uid'])); |
|||
if($zoreres){ |
|||
pdo_insert(PDO_NAME . 'credit2zero', ['uid'=>$userinfo['uid'],'uniacid'=>$_W['uniacid'],'createtime'=>time()]); |
|||
} |
|||
} |
|||
$flaguid = $userinfo['uid']; |
|||
$userinfo['uid'] = $uid; |
|||
if (0 < $member['credit1']) { |
|||
mc_credit_update($uid, 'credit1', $member['credit1'],array($uid, '合并用户数据修改积分,uid='.$flaguid, MODULE_NAME)); |
|||
$upgrade['credit1'] = 0; |
|||
$userinfo['credit1'] = 0; |
|||
} |
|||
if (0 < $member['credit2']) { |
|||
mc_credit_update($uid, 'credit2', $member['credit2'],array($uid, '合并用户数据修改余额,uid='.$flaguid, MODULE_NAME)); |
|||
$upgrade['credit2'] = 0; |
|||
$userinfo['credit2'] = 0; |
|||
} |
|||
}else if(!empty($member['uid'])){ |
|||
//公众号同步到小程序数据 |
|||
if($userinfo['uid'] != $member['uid']){ |
|||
$creditarray = pdo_get('mc_members',array('uid'=>$member['uid']),array('credit1','credit2')); |
|||
$member['credit1'] = $creditarray['credit1']; |
|||
$member['credit2'] = $creditarray['credit2']; |
|||
$zoreres = pdo_update('mc_members',array('credit1' => 0,'credit2' => 0),array('uid' => $member['uid'])); |
|||
if($zoreres){ |
|||
pdo_insert(PDO_NAME . 'credit2zero', ['uid'=>$member['uid'],'uniacid'=>$_W['uniacid'],'createtime'=>time()]); |
|||
} |
|||
} |
|||
$flaguid = $member['uid']; |
|||
if (0 < $member['credit1']) { |
|||
mc_credit_update($userinfo['uid'], 'credit1', $member['credit1'],array($userinfo['uid'], '合并用户数据修改积分,uid='.$flaguid, MODULE_NAME)); |
|||
$upgrade['credit1'] = 0; |
|||
$userinfo['credit1'] = 0; |
|||
} |
|||
if (0 < $member['credit2']) { |
|||
mc_credit_update($userinfo['uid'], 'credit2', $member['credit2'],array($userinfo['uid'], '合并用户数据修改余额,uid='.$flaguid, MODULE_NAME)); |
|||
$upgrade['credit2'] = 0; |
|||
$userinfo['credit2'] = 0; |
|||
} |
|||
} |
|||
|
|||
//对比用户信息,不同则更新 |
|||
if (empty($member['tokey'])) { |
|||
$upgrade['tokey'] = strtoupper(MD5(sha1(time() . random(12)))); |
|||
} |
|||
$fields = self::wl_member_update_fields(); |
|||
foreach ($fields as $field) { |
|||
if (!empty($userinfo[$field]) && $userinfo[$field] != $member[$field]) { |
|||
$upgrade[$field] = $userinfo[$field]; |
|||
} |
|||
} |
|||
if ($upgrade['nickname'] == '微信用户') { |
|||
unset($upgrade['nickname']); |
|||
unset($upgrade['encodename']); |
|||
unset($upgrade['avatar']); |
|||
} |
|||
pdo_update(PDO_NAME . 'member', $upgrade, array('id' => $member['id'])); |
|||
$member = array_merge($member, $upgrade); |
|||
|
|||
if ($member['uid']) { |
|||
$credit = pdo_get('mc_members', array('uid' => $member['uid']), array('credit1', 'credit2')); |
|||
$member['credit1'] = $credit['credit1'] + $member['credit1']; |
|||
$member['credit2'] = $credit['credit2'] + $member['credit2']; |
|||
} |
|||
|
|||
//同步分销商表 |
|||
if ($member['distributorid']) { |
|||
pdo_update('wlmerchant_distributor', array('mobile' => $member['mobile'], 'nickname' => $member['nickname'], 'realname' => $member['realname']), array('mid' => $member['id'])); |
|||
} |
|||
|
|||
return $member; |
|||
} |
|||
|
|||
/** |
|||
* 用户更新字段 |
|||
* @return array |
|||
*/ |
|||
private static function wl_member_update_fields() { |
|||
return ['uid', 'avatar', 'nickname', 'encodename','openid', 'wechat_openid', 'webapp_openid', 'unionid', 'mobile', 'password', 'salt', 'session_key', 'credit1', 'credit2']; |
|||
} |
|||
|
|||
/** |
|||
* 合并用户的账号 |
|||
* @param $keyval 合并关键内容的值 手机号 || unionid |
|||
* @param string $type mobile或unionid为关键 |
|||
* @return bool |
|||
*/ |
|||
static function wl_member_merge($keyval, $type = 'mobile') { |
|||
global $_W; |
|||
if (empty($keyval)) { |
|||
return error(1, '合并内容值不得为空'); |
|||
} |
|||
if (!in_array($type, ['mobile', 'unionid'])) { |
|||
return error(1, '合并类型错误,检查后重试'); |
|||
} |
|||
#1、获取符号条件的所账号信息 |
|||
$fields = self::wl_member_update_fields(); |
|||
$info = pdo_getall(PDO_NAME . "member", array('uniacid' => $_W['uniacid'], $type => $keyval), array_merge($fields, array('id', 'distributorid', 'tokey')), '', 'id asc'); |
|||
|
|||
#2、判断账号信息是否大于等于 2 条,是通过循环合并账号信息 否则不管 |
|||
if (count($info) < 2) { |
|||
return error(1, '不存在重复信息,无需合并'); |
|||
} |
|||
|
|||
#3、获取最早建立的账号 为主账号 |
|||
$earliest = $info[0]; |
|||
|
|||
#4、通过循环合并账号信息 |
|||
WeliamWeChat::startTrans();//开启事务处理 |
|||
foreach ($info as $key => $val) { |
|||
//修改的账号不包括最早建立的账号 |
|||
if ($val['id'] != $earliest['id']) { |
|||
//---4-1: 合并第一项内容 账号信息 合并内容:member表中 不同的openid,mobile,unionid |
|||
$userinfo = $val; |
|||
unset($userinfo['id'], $userinfo['distributorid'], $userinfo['tokey']); |
|||
self::wl_member_update($userinfo, $earliest['id']); |
|||
|
|||
//---4-2: 合并第二项内容 订单信息 合并内容:order订单表,rush_order订单表中的mid 全部改为最早账号的mid |
|||
//修改 order 订单表 |
|||
pdo_update(PDO_NAME . "order", array('mid' => $earliest['id']), array('mid' => $val['id'])); |
|||
//修改 rush_order 订单表 |
|||
pdo_update(PDO_NAME . "rush_order", array('mid' => $earliest['id']), array('mid' => $val['id'])); |
|||
//修改disorder 表 |
|||
pdo_update(PDO_NAME . "disorder", array('buymid' => $earliest['id']), array('buymid' => $val['id'])); |
|||
|
|||
//---4-3: 合并第三项内容 分销商信息 |
|||
if (empty($earliest['distributorid'])) { |
|||
$earliest['distributorid'] = $val['distributorid']; |
|||
} else if ($val['distributorid'] > 0) { |
|||
//修改distributor表 金额 下级 |
|||
$eardis = pdo_get('wlmerchant_distributor', array('id' => $earliest['distributorid']), array('dismoney', 'nowmoney', 'mid')); |
|||
$valdis = pdo_get('wlmerchant_distributor', array('id' => $val['distributorid']), array('dismoney', 'nowmoney', 'mid')); |
|||
if ($valdis['dismoney'] > 0) { |
|||
$newdismoney = sprintf("%.2f", $eardis['dismoney'] + $valdis['dismoney']); |
|||
pdo_update('wlmerchant_distributor', array('dismoney' => $newdismoney), array('id' => $earliest['distributorid'])); |
|||
} |
|||
if ($valdis['nowmoney'] > 0) { |
|||
$newnowmoney = sprintf("%.2f", $eardis['nowmoney'] + $valdis['nowmoney']); |
|||
pdo_update('wlmerchant_distributor', array('nowmoney' => $newnowmoney), array('id' => $earliest['distributorid'])); |
|||
} |
|||
pdo_update('wlmerchant_distributor', array('leadid' => $earliest['id']), array('leadid' => $val['id'])); |
|||
pdo_delete('wlmerchant_distributor', array('id' => $val['distributorid'])); |
|||
//修改disorder 分销订单表 |
|||
pdo_update('wlmerchant_disorder', array('oneleadid' => $earliest['distributorid']), array('oneleadid' => $val['distributorid'], 'status' => 0)); |
|||
pdo_update('wlmerchant_disorder', array('twoleadid' => $earliest['distributorid']), array('twoleadid' => $val['distributorid'], 'status' => 0)); |
|||
//修改disapply 分销商提现表 |
|||
pdo_update('wlmerchant_disapply', array('mid' => $earliest['id'], 'disid' => $earliest['distributorid']), array('mid' => $val['id'])); |
|||
} |
|||
|
|||
//---4-4: 合并第四项内容 商户信息 |
|||
//修改 merchantuser 将当前用户mid修改为最早账号的mid |
|||
pdo_update(PDO_NAME . "merchantuser", ['mid' => $earliest['id']], ['mid' => $val['id']]); |
|||
|
|||
#5、账号合并完成 当前账号的信息已经全部合并给最早建立的账号 删除当前账号 |
|||
pdo_delete(PDO_NAME . "member", array('id' => $val['id'])); |
|||
} |
|||
} |
|||
WeliamWeChat::commit();//提交事务信息 |
|||
|
|||
return $earliest; |
|||
} |
|||
|
|||
/* |
|||
* 更新积分信息 |
|||
*/ |
|||
static function credit_update_credit1($mid, $credit1 = 0, $remark = '', $orderno = '') { |
|||
global $_W; |
|||
$member = self::wl_member_get($mid); |
|||
$settings = Setting::wlsetting_read('base'); |
|||
if (empty($member)) { |
|||
return error(-1, '用户不存在'); |
|||
} |
|||
if (($member['credit1'] + $credit1) < 0) { |
|||
return error(-1, '用户积分不足'); |
|||
} |
|||
if(abs($credit1) > 0.01){ |
|||
//会员不存在uid时,更新模块本身的积分余额 |
|||
if (empty($member['uid'])) { |
|||
return error(-1, 'UID不存在,请重新登录'); |
|||
//$res = pdo_update(PDO_NAME . "member", array('credit1' => $member['credit1'] + $credit1), array('id' => $member['id'])); |
|||
} else { |
|||
load()->model('mc'); |
|||
if (empty($remark)) { |
|||
$remark = $settings['name'] ? $settings['name'] . '积分操作' : '智慧城市积分操作'; |
|||
} |
|||
$res = mc_credit_update($member['uid'], 'credit1', $credit1, array($member['uid'], $remark, MODULE_NAME)); |
|||
} |
|||
if(is_error($res)){ |
|||
return $res; |
|||
}else{ |
|||
$data = array('uid' => $member['uid'], 'uniacid' => $_W['uniacid'], 'mid' => $member['id'], 'num' => $credit1, 'createtime' => TIMESTAMP, 'type' => 1, 'remark' => $remark, 'ordersn' => $orderno); |
|||
pdo_insert(PDO_NAME . "creditrecord", $data); |
|||
$newCredit = pdo_getcolumn('mc_members',['uid' => $member['uid']],'credit1'); |
|||
//积分变更通知 |
|||
$trade = Setting::wlsetting_read('trade'); |
|||
$integralText = $trade['credittext'] ? : '积分'; |
|||
if(Customized::init('customized530') && $credit1 > 0){ |
|||
$payinfo = [ |
|||
'first' => "收益到账通知:", |
|||
'profit_money' => "{$credit1}{$integralText}",//收益金额 |
|||
'profit_source' => $remark,//收益来源 |
|||
'time' => date("Y年m月d日 Y:i:s",time()),//变更日期 |
|||
'remark' => '', |
|||
]; |
|||
TempModel::sendInit('profit',$member['id'],$payinfo,$_W['source']); |
|||
}else if(!Customized::init('customized530')){ |
|||
$integral = trim($credit1,'-'); |
|||
$payinfo = [ |
|||
'first' => "您的{$integralText}已发生变化", |
|||
'old_number' => "原有{$integralText}:{$member['credit1']},{$remark}:{$integral}",//原有数量 |
|||
'current_number' => "现有{$integralText}:{$newCredit}",//变更结果 |
|||
'time' => date("Y-m-d H:i:s",time()),//变更日期 |
|||
'remark' => "点击查看{$integralText}变更记录", |
|||
'change_num' => $credit1, |
|||
'balance' => $newCredit, |
|||
'change_remark' => $remark, |
|||
]; |
|||
$url = h5_url('pages/subPages/IntegralRecord/IntegralRecord'); |
|||
TempModel::sendInit('change',$member['id'],$payinfo,$_W['source'],$url); |
|||
} |
|||
} |
|||
return TRUE; |
|||
}else{ |
|||
return error(-1, '修改积分数额不正确'); |
|||
} |
|||
} |
|||
|
|||
/* |
|||
* 更新余额信息 |
|||
* |
|||
*/ |
|||
static function credit_update_credit2($mid, $credit2 = 0, $remark = '', $orderno = '') {//余额 |
|||
global $_W; |
|||
$member = self::wl_member_get($mid); |
|||
$settings = Setting::wlsetting_read('base'); |
|||
if (empty($member)) { |
|||
return error(-1, '用户不存在'); |
|||
} |
|||
if (($member['credit2'] + $credit2) < 0) { |
|||
return error(-1, '用户余额不足'); |
|||
} |
|||
if(abs($credit2)>0){ |
|||
//会员不存在uid时,更新模块本身的积分余额 |
|||
if (empty($member['uid'])) { |
|||
return error(-1, 'UID不存在,请重新登录'); |
|||
//pdo_update(PDO_NAME . "member", array('credit2' => $member['credit2'] + $credit2), array('id' => $member['id'])); |
|||
} else { |
|||
load()->model('mc'); |
|||
$header = $remark ? $settings['name'] . ':' : '智慧城市余额操作'; |
|||
$res = mc_credit_update($member['uid'], 'credit2', $credit2, array($member['uid'], $header . $remark, MODULE_NAME)); |
|||
} |
|||
if(is_error($res)){ |
|||
return $res; |
|||
}else { |
|||
$data = array('uid' => $member['uid'], 'uniacid' => $_W['uniacid'], 'mid' => $member['id'], 'num' => $credit2, 'createtime' => TIMESTAMP, 'type' => 2, 'remark' => $remark, 'ordersn' => $orderno); |
|||
pdo_insert(PDO_NAME . "creditrecord", $data); |
|||
} |
|||
} |
|||
return TRUE; |
|||
} |
|||
|
|||
//验证一卡通会员 |
|||
static function checkhalfmember($url = '') { |
|||
global $_W; |
|||
if (empty($_W['mid'])) { |
|||
Uniapp::renderError('未登录'); |
|||
} |
|||
$now = time(); |
|||
if ($_W['wlsetting']['halfcard']['halfcardtype'] == 2) { |
|||
$halfcardflag = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_halfcardmember') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} AND aid = {$_W['aid']} AND expiretime > {$now} AND disable != 1"); |
|||
} else { |
|||
$halfcardflag = pdo_fetch("SELECT id FROM " . tablename('wlmerchant_halfcardmember') . "WHERE uniacid = {$_W['uniacid']} AND mid = {$_W['mid']} AND expiretime > {$now} AND disable != 1"); |
|||
} |
|||
return $halfcardflag; |
|||
} |
|||
|
|||
static function payChargeNotify($params) { |
|||
global $_W; |
|||
Util::wl_log('payResult_notify', PATH_DATA . "merchant/data/", $params); //写入异步日志记录 |
|||
$order_out = pdo_get(PDO_NAME . 'order', array('orderno' => $params['tid'])); |
|||
$_W['uniacid'] = $order_out['uniacid']; |
|||
if ($order_out['status'] == 0 || $order_out['status'] == 5) { |
|||
$data = self::getVipPayData($params); //得到支付参数,处理代付 |
|||
if ($data['status'] == 1) { |
|||
$data['status'] = 3; |
|||
} |
|||
pdo_update(PDO_NAME . 'order', $data, array('orderno' => $params['tid'])); |
|||
$res1 = self::credit_update_credit2($order_out['mid'], $order_out['price'], '余额充值', $order_out['orderno']); |
|||
$settings = Setting::wlsetting_read('recharge'); |
|||
$count = count($settings['kilometre']); |
|||
for ($i = 0; $i < $count; $i++) { |
|||
$array[$i]['kilometre'] = $settings['kilometre'][$i]; |
|||
$array[$i]['kilmoney'] = $settings['kilmoney'][$i]; |
|||
} |
|||
$give = 0; |
|||
foreach ($array as $key => $val) { |
|||
$dos[$key] = $val['kilometre']; |
|||
} |
|||
array_multisort($dos, SORT_ASC, $array); |
|||
foreach ($array as $key => $ar) { |
|||
if ($order_out['price'] > $ar['kilometre'] || $order_out['price'] == $ar['kilometre']) { |
|||
$give = $ar['kilmoney']; |
|||
} |
|||
} |
|||
if ($give > 0) { |
|||
$res2 = self::credit_update_credit2($order_out['mid'], $give, '余额充值赠送', $order_out['orderno']); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static function payChargeReturn($params) { |
|||
wl_message('充值成功', h5_url('pages/mainPages/userCenter/userCenter')); |
|||
} |
|||
|
|||
static function getVipPayData($params) { |
|||
global $_W; |
|||
$data = array('status' => $params['result'] == 'success' ? 1 : 0); |
|||
if ($params['is_usecard'] == 1) { |
|||
$fee = $params['card_fee']; |
|||
$data['is_usecard'] = 1; |
|||
} else { |
|||
$fee = $params['fee']; |
|||
} |
|||
//$paytype = array('credit' => 1, 'wechat' => 2, 'alipay' => 3, 'delivery' => 4, 'wxapp' => 5); |
|||
$data['paytype'] = $params['type']; |
|||
if ($params['type'] == 'wechat') $data['transid'] = $params['tag']['transaction_id']; |
|||
$data['paytime'] = TIMESTAMP; |
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 生成微信用户信息 |
|||
* Author: zzw |
|||
* Date: 2020/3/9 10:32 |
|||
* @param $nickname |
|||
* @return mixed |
|||
*/ |
|||
public static function createUserInfo($nickname){ |
|||
global $_W; |
|||
$group_id = pdo_getcolumn('mc_groups', ['uniacid' => $_W['uniacid'], 'isdefault' => 1], 'groupid'); |
|||
$salt = random(8); |
|||
$data = [ |
|||
'uniacid' => $_W['uniacid'], |
|||
'salt' => $salt, |
|||
'groupid' => $group_id, |
|||
'createtime' => TIMESTAMP, |
|||
'nickname' => $nickname, |
|||
]; |
|||
//储存微擎用户数据信息 |
|||
pdo_insert('mc_members', $data); |
|||
$uid = pdo_insertid(); |
|||
return $uid; |
|||
} |
|||
|
|||
/** |
|||
* 修改商户关联用户身份 |
|||
* @param $storeid // 商户id |
|||
* @param $merchant_type // 商户类型 1-企业 2-商户 |
|||
* @return false|void |
|||
*/ |
|||
static function updateStoreUserIdentity($storeid,$merchant_type = '') { |
|||
if (empty($storeid)) return false; |
|||
$storeRes = pdo_get(PDO_NAME . 'merchantdata' , ['id' => $storeid] , ['status','merchant_type']); |
|||
if ($storeRes['status'] != 2) return false; |
|||
if (empty($merchant_type)) $merchant_type = $storeRes['merchant_type']; |
|||
$identity_id = $merchant_type == 1 ? 5 : 4; // 4 商家 5 企业 |
|||
$mid_res = pdo_getall(PDO_NAME . 'merchantuser', ['storeid' => $storeid, 'ismain' => 1],['mid']); |
|||
foreach ($mid_res as $mid_row) { |
|||
pdo_update(PDO_NAME . 'member',['identity_id' => $identity_id], ['id' => $mid_row['mid']]); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 商户企业身份 回退游客身份 |
|||
* @param $mid |
|||
*/ |
|||
static function returnIdentity($mid) |
|||
{ |
|||
$query = pdo_get(PDO_NAME . 'merchantuser',['mid' => $mid]); |
|||
if (!$query) { |
|||
$memberQuery = pdo_get(PDO_NAME.'member',['id' => $mid,'identity_id' => [4,5]],'identity_id'); |
|||
if ($memberQuery) { |
|||
pdo_update(PDO_NAME . 'member',['identity_id' => 1], ['id' => $mid]); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取用户头像和昵称 |
|||
* @param $data |
|||
* @param $mid |
|||
* @return false|void |
|||
*/ |
|||
static function getMemberInfo(&$data,$mid) { |
|||
if (!is_array($data)) return false; |
|||
$memberinfo = pdo_get(PDO_NAME.'member',array('id' => $mid),array('avatar','nickname','encodename')); |
|||
if (!$memberinfo) return false; |
|||
$data['nickname'] = base64_decode($memberinfo['encodename']); |
|||
$data['avatar'] = tomedia($memberinfo['avatar']); |
|||
} |
|||
|
|||
/** |
|||
* 验证用户身份是否可以认证 |
|||
* @param $mid // 用户ID |
|||
* @param $notIdentity // 是否进行身份验证 |
|||
* @return array|bool[] |
|||
*/ |
|||
static function validateMemberIdentity($mid,$notIdentity = true,$storePay = false) { |
|||
if (empty($mid)) return ['status' => true]; |
|||
|
|||
// 防止交叉申请认证 |
|||
$where = ['mid' => $mid, 'status' => 0]; |
|||
$student_res = pdo_get(PDO_NAME . 'member_student_info',['check_status' => 0, 'mid' => $mid],'id'); |
|||
if ($student_res) return ['status' => false, 'msg' => '学生身份认证审核中...,不可申请认证', 'identity' => '学生身份']; |
|||
$teacher_res = pdo_get(PDO_NAME . 'member_teacher_certified',$where,'id'); |
|||
if ($teacher_res) return ['status' => false, 'msg' => '教师身份认证审核中...,不可申请认证', 'identity' => '教师身份']; |
|||
$blogger_res = pdo_get(PDO_NAME . 'member_daren_certified',$where,'id'); |
|||
if ($blogger_res) return ['status' => false, 'msg' => '达人身份认证审核中...,不可申请认证', 'identity' => '达人身份']; |
|||
$user_res = pdo_get(PDO_NAME . 'merchantuser',['mid' => $mid],['storeid']); |
|||
if ($user_res) { |
|||
$statusArr = $storePay ? 1 : [0,1]; |
|||
$merchant_res = pdo_get(PDO_NAME . 'merchantdata',['id' => $user_res['storeid'], 'status' => $statusArr],['id','status']); |
|||
if ($merchant_res) { |
|||
$str = $merchant_res['status'] == 1 ? '审核' : '待支付'; |
|||
return ['status' => false, 'msg' => '企业身份认证'.$str.'中...,不可申请认证', 'identity' => '企业身份']; |
|||
} |
|||
} |
|||
|
|||
// 认证身份是否可以申请 |
|||
if ($notIdentity) { |
|||
$member = pdo_get(PDO_NAME . 'member',['id' => $mid],['identity_id']); |
|||
if (in_array($member['identity_id'],[1,3])) return ['status' => true]; |
|||
$identity = pdo_get(PDO_NAME . 'member_identity',['id' => $member['identity_id']],'name'); |
|||
return ['status' => false, 'msg' => '当前用户已是'.$identity['name'].'身份,不可申请认证', 'identity' => $identity['name'].'身份']; |
|||
} |
|||
return ['status' => true]; |
|||
} |
|||
|
|||
/** |
|||
* 申请变更身份的用户 |
|||
* @return array |
|||
*/ |
|||
static function applyChangeInentityUser() |
|||
{ |
|||
$midArr = []; |
|||
$student_res = pdo_getall(PDO_NAME . 'member_student_info',['check_status' => 0],'mid'); |
|||
foreach ($student_res as $student_row) $midArr[] = $student_row['mid']; |
|||
$teacher_res = pdo_getall(PDO_NAME . 'member_teacher_certified',['status' => 0],'mid'); |
|||
foreach ($teacher_res as $teacher_row) $midArr[] = $teacher_row['mid']; |
|||
$blogger_res = pdo_getall(PDO_NAME . 'member_daren_certified',['status' => 0],'mid'); |
|||
foreach ($blogger_res as $blogger_row) $midArr[] = $blogger_row['mid']; |
|||
$user_sql = "select a.mid from ".tablename('wlmerchant_merchantuser')." as a join ".tablename('wlmerchant_merchantdata')." as b " |
|||
." on a.storeid = b.id where a.enabled = 1 and a.status in (0,1) and b.status in (0,1)"; |
|||
$user_res = pdo_fetch($user_sql); |
|||
foreach ($user_res as $user_row) $midArr[] = $user_row['mid']; |
|||
return array_unique($midArr); |
|||
} |
|||
|
|||
/** |
|||
* 验证用户权限 |
|||
* @param $mid |
|||
* @param $key |
|||
* @param $member |
|||
* @return array|bool[] |
|||
*/ |
|||
public static function validateMemberRights($mid,$key,$member = []) |
|||
{ |
|||
if (empty($member)) { |
|||
$member = pdo_get(PDO_NAME . 'member',['id' => $mid]); |
|||
} |
|||
$rights = $member['rights']; |
|||
$rightsInfo = $rights ? unserialize($rights) : []; // 用户权限 |
|||
# 校园活动发布是否显示 判断用户是否有权限 是否有校园活动发布权限 |
|||
|
|||
switch ($key) { |
|||
case 'campus_activities': |
|||
if (!isset($rightsInfo[$key]) || $rightsInfo[$key] != 1) { |
|||
return ['status' => false, 'msg' => '您未开通校园活动发布权限,无法访问']; |
|||
} |
|||
break; |
|||
case '未完待续': |
|||
break; |
|||
} |
|||
return ['status' => true]; |
|||
} |
|||
|
|||
/** |
|||
* 递归删除校园活动评论 |
|||
*/ |
|||
static function commentDelete($id) |
|||
{ |
|||
global $_W; |
|||
if (empty($id)) return false; |
|||
$arr = pdo_getall(PDO_NAME . 'member_evaluation_activities' , ['uniacid' => $_W['uniacid'] , 'pid' => $id]); |
|||
if (empty($arr)) return pdo_delete(PDO_NAME . 'member_evaluation_activities' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
foreach ($arr as $key => $value) { |
|||
if (!self::commentDelete($value['id'])) return false; |
|||
} |
|||
return pdo_delete(PDO_NAME . 'member_evaluation_activities' , ['uniacid' => $_W['uniacid'] , 'id' => $id]); |
|||
} |
|||
} |
|||
@ -0,0 +1,115 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class MysqlFunction { |
|||
/** |
|||
* Comment: [由于数据库权限问题,当前方法弃用]创建数据库方法 —— 距离获取(需要数据库存在lng,lat两个字段才能使用) |
|||
* Author: zzw |
|||
* Date: 2019/12/16 18:36 |
|||
* @param string $tableName 表名称(非全名;例如:citycard_lists) |
|||
*/ |
|||
public static function getDistance($tableName){ |
|||
$table = tablename(PDO_NAME.$tableName); |
|||
$functionName = "get_distance_{$tableName}"; |
|||
//判断方法是否存在 |
|||
$isHave = pdo_fetch(" SHOW CREATE FUNCTION {$functionName};"); |
|||
if(!$isHave){ |
|||
$functionSql = "CREATE FUNCTION {$functionName}(object_lat VARCHAR(16),object_lng VARCHAR(16),object_id INT(11)) RETURNS FLOAT |
|||
BEGIN |
|||
DECLARE distances DOUBLE DEFAULT 0; |
|||
SELECT |
|||
CASE |
|||
WHEN object_lat > 0 AND object_lng > 0 THEN ROUND(6378.138 * 2 * ASIN( |
|||
SQRT( |
|||
POW(SIN((object_lat * PI() / 180 - lat * PI() / 180) / 2),2) + |
|||
COS(object_lat * PI() / 180) * COS(lat * PI() / 180) * |
|||
POW(SIN((object_lng * PI() / 180 - lng * PI() / 180) / 2),2) |
|||
) |
|||
) * 1000 |
|||
) |
|||
ELSE 0 |
|||
END INTO distances FROM ".$table." WHERE id = object_id; |
|||
RETURN distances; |
|||
END"; |
|||
pdo_fetch($functionSql);//建立方法 |
|||
} |
|||
//$list = pdo_fetch("SELECT {$functionName}({$lat},{$lng},6)");//使用方法 |
|||
//pdo_fetch(" DROP FUNCTION {$functionName};");//删除方法 |
|||
} |
|||
/** |
|||
* Comment: [由于数据库权限问题,当前方法弃用]获取总数 |
|||
* Author: zzw |
|||
* Date: 2019/12/17 10:37 |
|||
* @param string $tableName 表名称 |
|||
* @param int $field 条件字段(id) |
|||
*/ |
|||
public static function getCount($tableName,$field){ |
|||
$table = tablename(PDO_NAME.$tableName); |
|||
$functionName = "get_count_{$tableName}"; |
|||
//判断方法是否存在 |
|||
$isHave = pdo_fetch(" SHOW CREATE FUNCTION {$functionName};"); |
|||
if(!$isHave){ |
|||
$functionSql = "CREATE FUNCTION {$functionName}(id int(11)) RETURNS INT |
|||
BEGIN |
|||
DECLARE count_num DOUBLE DEFAULT 0; |
|||
SELECT COUNT(*) INTO count_num FROM ".$table." WHERE {$field} = id; |
|||
RETURN count_num; |
|||
END"; |
|||
pdo_fetch($functionSql);//建立方法 |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 设置隔离等级 |
|||
* Author: wlf |
|||
* Date: 2020/01/02 16:42 |
|||
* @return string $level 隔离等级 (1 READ UNCOMMITTED 读未提交 2 READ COMMITTED 读提交 3 REPEATABLE READ 可重复读 4 SERIALIZABLE 串行化) |
|||
*/ |
|||
public function setTrans($level = 1){ |
|||
switch ($level){ |
|||
case 1: |
|||
$levelset = 'READ UNCOMMITTED'; |
|||
break; |
|||
case 2: |
|||
$levelset = 'READ COMMITTED'; |
|||
break; |
|||
case 3: |
|||
$levelset = 'REPEATABLE READ'; |
|||
break; |
|||
case 4: |
|||
$levelset = 'SERIALIZABLE'; |
|||
break; |
|||
} |
|||
return pdo_query(" SET SESSION TRANSACTION ISOLATION LEVEL {$levelset}"); |
|||
} |
|||
/** |
|||
* Comment: 开启事务处理 |
|||
* Author: zzw |
|||
* Date: 2019/8/15 11:47 |
|||
* @return bool |
|||
*/ |
|||
public function startTrans(){ |
|||
return pdo_query(" BEGIN "); |
|||
} |
|||
/** |
|||
* Comment: 提交事务处理 |
|||
* Author: zzw |
|||
* Date: 2019/8/15 11:47 |
|||
* @return bool |
|||
*/ |
|||
public function commit(){ |
|||
return pdo_query(" COMMIT "); |
|||
} |
|||
/** |
|||
* Comment: 事务回滚 |
|||
* Author: zzw |
|||
* Date: 2019/8/15 11:47 |
|||
* @return bool |
|||
*/ |
|||
public function rollback(){ |
|||
return pdo_query(" ROLLBACK "); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,152 @@ |
|||
<?php |
|||
class Pay{ |
|||
static function createVipOrder(){ |
|||
global $_W; |
|||
$activity = self::getSingleActive($id, '*'); |
|||
$random = Util::createSalt(); |
|||
$vipInfo = Util::getSingelData('*', PDO_NAME."member", array('uniacid'=>$_W['uniacid'],'mid'=>$_W['mid'])); |
|||
$data = array( |
|||
'uid' =>$vipInfo['uid'], |
|||
'uniacid' => $_W['uniacid'], |
|||
'unionid' => $_W['unionid'], |
|||
'mid' => $_W['mid'], |
|||
'openid' => $_W['openid'], |
|||
'areaid' => $_W['areaid'], |
|||
'orderno' => "VIP_".createUniontid(), |
|||
'status' => 0,//订单状态:0未支,1支付,2待发货,3已发货,4已签收,5已取消,6待退款,7已退款 |
|||
'createtime' => TIMESTAMP, |
|||
'price' => $activity['price'] |
|||
); |
|||
pdo_insert(PDO_NAME.'vip_record',$data); |
|||
return pdo_insertid(); |
|||
|
|||
} |
|||
static function getCash($paytype,$orderno,$name,$price,$plugin,$done=''){ |
|||
global $_W; |
|||
load()->func('communication'); |
|||
$moduels = uni_modules(); |
|||
$plugins = getAllPluginsName(); |
|||
|
|||
if(empty($orderno)) wl_message(array('errno'=>1,'message'=>"参数错误,缺少订单号.")); //验证是否缺失订单号。 |
|||
|
|||
|
|||
|
|||
if($price <= 0) wl_message(array('errno'=>1,'message'=>"支付金额错误,支付金额需大于0元."));//验证支付金额是否大于0。 |
|||
|
|||
$params['tid'] = $orderno; |
|||
$params['user'] = $_W['openid']; |
|||
$params['fee'] = $price; |
|||
$params['title'] = $name; |
|||
$params['ordersn'] = $orderno; |
|||
$params['module'] = MODULE_NAME; |
|||
$params['plugin'] = $plugin; |
|||
|
|||
if(!array_key_exists($params['module'], $moduels)) wl_message('模块不存在.');//若模块不在微擎则报错。 |
|||
if(!in_array($params['plugin'], $plugins)) wl_message('插件不存在.');//若模块不在微擎则报错。 |
|||
|
|||
$pars = array(); |
|||
$pars['uniacid'] = $_W['uniacid']; |
|||
$pars['module'] = $params['module']; |
|||
$pars['plugin'] = $params['plugin']; |
|||
$pars['tid'] = $params['tid']; |
|||
|
|||
$log = pdo_get(PDO_NAME.'paylogvfour',$pars); //当前订单已存在则取出 |
|||
|
|||
if($done == 1) { //支付成功后 点击完成按钮执行。 |
|||
if(empty($log)) wl_debug("log empty!"); //若$log为空打印error并退出。 |
|||
if (!empty($log['tag'])) { |
|||
$tag = iunserializer($log['tag']); |
|||
$log['uid'] = $tag['uid']; |
|||
} |
|||
$ret = array(); |
|||
$ret['weid'] = $log['uniacid']; |
|||
$ret['uniacid'] = $log['uniacid']; |
|||
$ret['result'] = 'success'; |
|||
$ret['type'] = $log['type']; |
|||
$ret['from'] = 'return'; |
|||
$ret['tid'] = $log['tid']; |
|||
$ret['uniontid'] = $log['uniontid']; |
|||
$ret['user'] = $log['openid']; |
|||
$ret['fee'] = $log['fee']; |
|||
$ret['tag'] = $tag; |
|||
$ret['is_usecard'] = $log['is_usecard']; |
|||
$ret['card_type'] = $log['card_type']; |
|||
$ret['card_fee'] = $log['card_fee']; |
|||
$ret['card_id'] = $log['card_id']; |
|||
exit(self::payReturn($ret)); |
|||
} |
|||
if ($_W['isajax']) { |
|||
$dos = array(); |
|||
$setting = uni_setting($_W['uniacid'], array('payment', 'creditbehaviors')); |
|||
if(!is_array($setting['payment'])) wl_message(array('errno'=>1,'message'=>"没有有效的支付方式, 请联系网站管理员.")); //判断微擎是否有支付设置内容。 |
|||
if(!empty($setting['payment']['credit']['switch'])) $dos[] = 'credit'; |
|||
if(!empty($setting['payment']['alipay']['switch'])) $dos[] = 'alipay'; |
|||
if(!empty($setting['payment']['wechat']['switch'])) $dos[] = 'wechat'; |
|||
|
|||
$type = in_array($paytype, $dos) ? $paytype : ''; |
|||
if(empty($type)) wl_message(array('errno'=>1,'message'=>"支付方式错误,请联系商家")); |
|||
|
|||
$data = array( |
|||
'uniacid' => $order['uniacid'] ? : $_W['uniacid'] , |
|||
'source' => $_W['source'] , |
|||
'acid' => $_W['acid'] , |
|||
'openid' => $_W['openid'] , |
|||
'module' => $params['module'] , |
|||
'plugin' => $params['plugin'] , |
|||
'tid' => $params['tid'] , |
|||
'fee' => $params['fee'] , |
|||
'card_fee' => $params['fee'] , |
|||
'status' => '0' , |
|||
'is_usecard' => '0' , |
|||
'type' => $type //支付方式 |
|||
); |
|||
if (empty($log)) pdo_insert(PDO_NAME.'paylogvfour', $data); //生成paylog记录 |
|||
|
|||
$log = pdo_get(PDO_NAME.'paylogvfour',$pars); //获得新的支付记录 |
|||
if(!empty($log) && $type != 'credit' && $log['status'] != '0') wl_message(array('errno'=>1,'message'=>"这个订单已经支付成功, 不需要重复支付!")); |
|||
$uniontid = createUniontid(); //生成商户订单号 |
|||
|
|||
pdo_update(PDO_NAME.'paylogvfour', array('type'=>$type,'uniontid'=>$uniontid), array('plid' => $log['plid'])); //更新type和uniontid到微擎core_paylog。 |
|||
|
|||
$log = pdo_get(PDO_NAME.'paylogvfour',$pars); //更新后再次取出支付记录。 |
|||
|
|||
if($type == 'wechat') { //微信支付 |
|||
$wechat = $setting['payment']['wechat']; |
|||
|
|||
$payset = Setting::wlsetting_read('payset'); |
|||
$partner = unserialize($payset['partner']); |
|||
|
|||
$row = pdo_fetch('SELECT `key`,`secret` FROM ' . tablename('account_wechats') . ' WHERE `acid`=:acid', array(':acid' => $wechat['account'])); |
|||
$wechat['appid'] = $row['key']; |
|||
$wechat['secret'] = $row['secret']; |
|||
$params = array( |
|||
'tid' => $log['tid'], |
|||
'fee' => $log['card_fee'], |
|||
'user' => $log['openid'], |
|||
'title' => $params['title'], |
|||
'uniontid' => $log['uniontid'], |
|||
); |
|||
if($payset['wechatstatus'] == 2){ |
|||
$wechat['appid'] = $partner['appid']; |
|||
$wechat['secret'] = $partner['appsecret']; |
|||
$wechat['mchid'] = $partner['mchid']; |
|||
$wechat['sub_mch_id'] = $partner['submchid']; |
|||
$wechat['sub_appid'] = $partner['chappid']; |
|||
} |
|||
$notify_url = MODULE_URL . 'payment/wechat/weixin_notify.php'; |
|||
$wOpt = PayBuild::wechat_build($params, $wechat,$notify_url); |
|||
if (is_error($wOpt)) { |
|||
if ($wOpt['message'] == 'invalid out_trade_no' || $wOpt['message'] == 'OUT_TRADE_NO_USED') { |
|||
$id = date('YmdH'); |
|||
pdo_update(PDO_NAME.'paylogvfour', array('plid' => $id), array('plid' => $log['plid'])); |
|||
pdo_query("ALTER TABLE ".tablename(PDO_NAME.'paylogvfour')." auto_increment = ".($id+1).";"); |
|||
wl_message(array('errno'=>1,'message'=>"抱歉,发起支付失败,系统已经修复此问题,请重新尝试支付。")); |
|||
} |
|||
wl_message(array('errno'=>1,'message'=>"抱歉,发起支付失败,具体原因为:“{$wOpt['errno']}:{$wOpt['message']}”。请及时联系站点管理员。")); |
|||
} |
|||
} |
|||
die(json_encode(array('errno'=>0,'message'=>"支付成功!",'data'=>$wOpt))); |
|||
} |
|||
|
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,158 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Copyright (c) 2015-2020 http://www.weliam.cn All rights reserved. |
|||
// +---------------------------------------------------------------------- |
|||
// | Describe: |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: startingline<916345570@qq.com> |
|||
// +---------------------------------------------------------------------- |
|||
class Perms{ |
|||
/** |
|||
* 获取所有功能 |
|||
* |
|||
* @access public |
|||
* @name allParms |
|||
* @return array |
|||
*/ |
|||
static function allParms(){ |
|||
// $parms = array( |
|||
// 'dashboard' => $this->permDashboard(), |
|||
// 'store' => $this->permStore(), |
|||
// 'member' => $this->permMember(), |
|||
// 'area' => $this->permArea(), |
|||
// 'app' => $this->permApp(), |
|||
// 'setting' => $this->permSetting() |
|||
// ); |
|||
$parms = array( |
|||
'dashboard' => self::permDashboard(), |
|||
'store' => self::permStore(), |
|||
'member' => self::permMember(), |
|||
'area' => self::permArea(), |
|||
'app' => self::permApp(), |
|||
'setting' => self::permSetting() |
|||
); |
|||
} |
|||
|
|||
protected function permDashboard(){ |
|||
$func = array( |
|||
'text' => "首页", |
|||
'adv' => array( |
|||
'text' => "幻灯片", |
|||
), |
|||
'nav' => array( |
|||
'text' => "导航图标", |
|||
), |
|||
'banner' => array( |
|||
'text' => "广告", |
|||
), |
|||
'sort' => array( |
|||
'text' => "排版设置", |
|||
), |
|||
'notice' => array( |
|||
'text' => "公告管理", |
|||
), |
|||
'cube' => array( |
|||
'text' => "魔方设置", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
protected function permStore(){ |
|||
$func = array( |
|||
'text' => "商户", |
|||
'regiseter' => array( |
|||
'text' => "入驻申请", |
|||
), |
|||
'user' => array( |
|||
'text' => "商户管理", |
|||
), |
|||
'group' => array( |
|||
'text' => "商户分组", |
|||
), |
|||
'category' => array( |
|||
'text' => "商户分类", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
protected function permMember(){ |
|||
$func = array( |
|||
'text' => "会员", |
|||
'member' => array( |
|||
'text' => "会员概况", |
|||
), |
|||
'list' => array( |
|||
'text' => "会员管理", |
|||
), |
|||
'level' => array( |
|||
'text' => "会员等级", |
|||
), |
|||
'group' => array( |
|||
'text' => "会员分组", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
protected function permArea(){ |
|||
$func = array( |
|||
'text' => "区域", |
|||
'basic' => array( |
|||
'text' => "区域概况", |
|||
), |
|||
'agent' => array( |
|||
'text' => "代理管理", |
|||
), |
|||
'selfarea' => array( |
|||
'text' => "自营地区", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
protected function permApp(){ |
|||
$func = array( |
|||
'text' => "应用", |
|||
'plugins' => array( |
|||
'text' => "应用展示", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
protected function permSetting(){ |
|||
$func = array( |
|||
'text' => "设置", |
|||
'shopset' => array( |
|||
'text' => "商城设置", |
|||
), |
|||
'payset' => array( |
|||
'text' => "支付方式", |
|||
), |
|||
'noticeset' => array( |
|||
'text' => "消息提醒", |
|||
), |
|||
'coverset' => array( |
|||
'text' => "入口设置", |
|||
) |
|||
); |
|||
return $func; |
|||
} |
|||
|
|||
/** |
|||
* 获取角色权限 |
|||
* |
|||
* @access public |
|||
* @name getRolePerm |
|||
* @param $roleid 角色id |
|||
* @return array |
|||
*/ |
|||
public function getRolePerms($roleid){ |
|||
global $_W; |
|||
if(empty($roleid)) return array(); |
|||
$rolePerms = Util::getDateByCacheFirst('model','perms',array('Util','getSingleDataInSingleTable'),array('wlmerchant',array('uniacid'=>$_W['uniacid'],'id'=>$roleid))); |
|||
return unserialize($rolePerms['perms']); |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,388 @@ |
|||
<?php |
|||
/** |
|||
* Comment: 定制小票打印接口 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 |
|||
* Time: 10:31 |
|||
*/ |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Printing{ |
|||
protected static $orderInfo,//订单信息 |
|||
$tid,//订单号 |
|||
$storeInfo,//商户信息 |
|||
$timeStamp,//当前时间 时间戳 |
|||
$userInfo;//用户信息 |
|||
/** |
|||
* Comment: 打印推送消息接口 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 11:13 |
|||
* @param string|int $tid |
|||
* @return array|bool|mixed |
|||
*/ |
|||
public static function init($tid){ |
|||
global $_W; |
|||
#1、信息获取 |
|||
self::$tid = $tid; |
|||
self::$timeStamp = time(); |
|||
self::getOrder();//订单信息获取 |
|||
if(!self::$orderInfo['sid']) { |
|||
Util::wl_log('printing' , PATH_MODULE . "log/" , [ |
|||
'error' => '商户id不存在' , |
|||
'tid' => $tid |
|||
] , '打印推送消息 —— 错误记录'); //写入日志记录 |
|||
return error(0 , '商户id不存在'); |
|||
} |
|||
self::getStore();//商户信息获取 |
|||
//self::getUser();//用户信息获取 |
|||
//判断是否开启打印推送 |
|||
if(self::$storeInfo['state'] != 1) { |
|||
Util::wl_log('printing' , PATH_MODULE . "log/" , [ |
|||
'error' => '未开启打印推送' , |
|||
'tid' => $tid, |
|||
'sid' => self::$orderInfo['sid'] , |
|||
'storename' => self::$storeInfo['storename'] |
|||
] , '打印推送消息 —— 错误记录'); //写入日志记录 |
|||
return error(0 , '未开启打印推送'); |
|||
} |
|||
//获取打印设置信息 |
|||
$printUrl = $_W['siteroot'] . 'addons/' . MODULE_NAME . '/requests/printing.php?tid='.self::$orderInfo['orderno']; |
|||
|
|||
$openid = self::$storeInfo['openid']; |
|||
$secret = self::$storeInfo['secret']; |
|||
#2、信息配置 |
|||
$payType = self::getPayType(self::$orderInfo['paytype']);//支付方式获取 |
|||
//https://citydev.weliam.com.cn/addons/weliam_smartcity/requests/printing.php?tid=2020040818053400013924445846 |
|||
$platform = unserialize(pdo_getcolumn(PDO_NAME."setting",['key'=>'base'],'value'));//平台设置信息获取 |
|||
$name = $platform['name'] ? : '乌卡拉'; |
|||
$data = [ |
|||
'userAccount' => self::$storeInfo['userAccount'] ,//操作员 |
|||
'title' => $payType ,//消息标题 |
|||
'click' => h5_url('pages/subPages/orderList/orderList'),//点击消息打开的链接 |
|||
'broadcast' => $name.'订单'.self::$orderInfo['price']."元" ,//语音播报内容(此项为空时,播报title) |
|||
'printUrl' => $printUrl,//打印url |
|||
'action' => 'PlatformBusiness' ,//事件处理(如qd11云打印:Printer,区分大小写) |
|||
]; |
|||
$first = strpos($data['click'],'&aid='); |
|||
$data['click'] = substr($data['click'],0,$first); |
|||
try { |
|||
#3、发送请求 |
|||
$controllerName = 'OpenApi'; |
|||
$json_data = json_encode ( $data ); |
|||
$Signature = strtoupper ( md5 ( $openid . $secret . self::$timeStamp . $json_data ) ); |
|||
$url = "http://openapi.1card1.cn/" . $controllerName . "/PushMessage?openId=" . $openid . "&signature=" . $Signature . "×tamp=" . self::$timeStamp; |
|||
$postData = "data=" . $json_data; |
|||
$result_data = self::postData ( $url, $postData ); |
|||
$result = json_decode ( $result_data, true ); |
|||
#4、记录日志 |
|||
$result['time'] = date("Y-m-d H:i:s",time()); |
|||
$result['orderno'] = self::$orderInfo['orderno']; |
|||
$result['data'] = $data; |
|||
Util::wl_log('printing', PATH_MODULE."log/",$result,'打印推送消息 —— 操作结果'); //写入日志记录 |
|||
|
|||
return $result; |
|||
} catch (\Throwable $e) { |
|||
$result['msg'] = $e->getMessage(); |
|||
$result['orderno'] = self::$orderInfo['orderno']; |
|||
Util::wl_log('printing', PATH_MODULE."log/",$result,'打印推送消息 —— 错误记录'); //写入日志记录 |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 订单信息获取 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 9:09 |
|||
* @param $order_no |
|||
* @return bool |
|||
*/ |
|||
protected static function getOrder(){ |
|||
global $_W; |
|||
#1、获取查询条件 |
|||
$where = " tid = ".self::$tid; |
|||
|
|||
#2、获取订单信息 |
|||
$orderInfo = pdo_fetch("SELECT mid,tid as orderno,fee as price,source,plugin,payfor FROM" .tablename(PDO_NAME.'paylogvfour') ." WHERE {$where} "); |
|||
if(empty($orderInfo)){ |
|||
$paylogid = pdo_getcolumn(PDO_NAME.'order',array('orderno' => self::$tid),'paylogid'); |
|||
$orderInfo = pdo_fetch("SELECT mid,tid as orderno,fee as price,source,plugin,payfor FROM" .tablename(PDO_NAME.'paylogvfour') ." WHERE plid = {$paylogid} "); |
|||
} |
|||
if($orderInfo['plugin']=='Citydelivery'){ |
|||
$orderInfo = []; |
|||
$orderInfo['orderno'] = self::$tid; |
|||
} |
|||
#3、处理获取的信息 |
|||
$orderInfo['mid'] = $orderInfo['mid'] > 0 ? $orderInfo['mid'] : $_W['mid']; |
|||
#3、获取商户id |
|||
$infoWhere = " WHERE orderno = {$orderInfo['orderno']} "; |
|||
if($orderInfo['plugin'] == 'Rush'){ |
|||
$field = " sid,paytype,paytime,mid,price as goodsprice,activityid as goods_id "; |
|||
$table = tablename(PDO_NAME."rush_order"); |
|||
}else{ |
|||
$field = " sid,paytype,payfor,paytime,mid,price,goodsprice,fkid as goods_id "; |
|||
$table = tablename(PDO_NAME."order"); |
|||
} |
|||
$order = pdo_fetch("SELECT {$field} FROM ".$table.$infoWhere); |
|||
//计算优惠金额 |
|||
$order['discount'] = sprintf("%0.2f",$order['goodsprice'] - $orderInfo['price']); |
|||
if($order['payfor'] == 'deliveryOrder'){ |
|||
$order['payfor'] = 'DeliveryOrder'; |
|||
$order['discount'] = 0; |
|||
} |
|||
self::$orderInfo = ($order + $orderInfo); |
|||
} |
|||
/** |
|||
* Comment: 获取商户信息 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 9:54 |
|||
*/ |
|||
protected static function getStore(){ |
|||
//获取商户信息 |
|||
$store = pdo_get(PDO_NAME."merchantdata",['id'=>self::$orderInfo['sid']],['storename','printing']); |
|||
//处理推送信息 |
|||
$printing = unserialize($store['printing']) ? :[]; |
|||
unset($store['printing']); |
|||
//合并生成新的商户设置信息 |
|||
$store = ($store + $printing); |
|||
$store['state'] = $store['state'] ? $store['state'] : 0; |
|||
|
|||
self::$storeInfo = $store; |
|||
} |
|||
/** |
|||
* Comment: 获取用户信息 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 10:38 |
|||
*/ |
|||
protected static function getUser(){ |
|||
//用户信息获取 |
|||
$user = pdo_get(PDO_NAME."member",['id'=>self::$orderInfo['mid']] ,['nickname']); |
|||
//会员等级获取 |
|||
$default = Setting::wlsetting_read('halflevel')['name'] ? : '普通会员' ; |
|||
$lvId = pdo_getcolumn(PDO_NAME . "halfcardmember" , [ |
|||
'mid' => self::$orderInfo['mid'] , |
|||
'disable' => 0 , |
|||
] , 'levelid'); |
|||
if($lvId) $lvTitle = pdo_getcolumn(PDO_NAME."halflevel",['id'=>$lvId],'name'); |
|||
$user['lv'] = $lvTitle ? $lvTitle : $default; |
|||
|
|||
self::$userInfo = $user; |
|||
} |
|||
/** |
|||
* Comment: 配置参数信息获取 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 15:48 |
|||
* @return false|mixed|string |
|||
*/ |
|||
protected static function getData(){ |
|||
#1、基本信息获取 |
|||
$payType = self::getPayType();//支付方式获取 |
|||
$payProject = self::getPayProject();//支付项目获取 |
|||
$platform = unserialize(pdo_getcolumn(PDO_NAME."setting",['key'=>'base'],'value'));//平台设置信息获取 |
|||
#2、信息配置 //'Content2'=>null |
|||
if(self::$storeInfo['header']){ |
|||
//图片处理 |
|||
$images = tomedia(self::$storeInfo['header']); |
|||
$images = str_replace('requests/','',$images); |
|||
$Type = 'Image'; |
|||
$Content = $images; |
|||
}else { |
|||
$Type = 'String'; |
|||
$Content = ' '.$platform['name']; |
|||
} |
|||
//处理同城配送订单信息 |
|||
if(self::$orderInfo['payfor']== 'DeliveryOrder'){ |
|||
$neworderinfo = pdo_get('wlmerchant_order',array('orderno' => self::$orderInfo['orderno']),array('buyremark','status','goodsprice','vipdiscount','expressprcie','expressid')); |
|||
self::$orderInfo['goodsprice'] = $neworderinfo['goodsprice']; |
|||
self::$orderInfo['discount'] = $neworderinfo['vipdiscount']; |
|||
} |
|||
|
|||
$data1 = [ |
|||
['Type' => $Type , 'Content' =>$Content], |
|||
['Type' => 'String' , 'Content' => ' 店面:' . self::$storeInfo['storename']] , |
|||
['Type' => 'String' , 'Content' => '支付时间:' . date("Y-m-d H:i:s" , self::$orderInfo['paytime'])] , |
|||
['Type' => 'String' , 'Content' => ' 订单号:' . self::$orderInfo['orderno']] , |
|||
['Type' => 'String' , 'Content' => ' 操作员:' . self::$storeInfo['userAccount']] , |
|||
['Type' => 'String' , 'Content' => '--------------------------------'] , |
|||
['Type' => 'String' , 'Content' => '业务类型:在线支付'] , |
|||
['Type' => 'String' , 'Content' => '支付方式:' . $payType] , |
|||
]; |
|||
|
|||
if(!is_array($payProject)){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '支付项目:' . $payProject]; |
|||
}else{ |
|||
foreach ($payProject as $ke => $ject){ |
|||
if($ke == 0){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '支付项目:' . $ject]; |
|||
}else{ |
|||
$data1[] = ['Type' => 'String' , 'Content' => ' ' . $ject]; |
|||
} |
|||
} |
|||
} |
|||
if(!empty($neworderinfo['buyremark'])){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '买家备注:'.$neworderinfo['buyremark']]; |
|||
} |
|||
if($neworderinfo['status'] == 1){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '配送方式:到店自提']; |
|||
}else if($neworderinfo['status'] == 4){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '配送方式:商家配送']; |
|||
} |
|||
if(!empty($neworderinfo['expressid'])){ |
|||
$express = pdo_get('wlmerchant_express',array('id' => $neworderinfo['expressid']),array('name','tel','address')); |
|||
$data1[] = ['Type' => 'String' , 'Content' => '收货人:'.$express['name']]; |
|||
$data1[] = ['Type' => 'String' , 'Content' => '联系电话:'.$express['tel']]; |
|||
$data1[] = ['Type' => 'String' , 'Content' => '配送地址:'.$express['address']]; |
|||
} |
|||
|
|||
$data1[] = ['Type' => 'String' , 'Content' => '商品金额:' . self::$orderInfo['goodsprice']]; |
|||
$data1[] = ['Type' => 'String' , 'Content' => '折扣优惠:' . self::$orderInfo['discount']]; |
|||
if($neworderinfo['expressprcie']>0){ |
|||
$data1[] = ['Type' => 'String' , 'Content' => '配送费用:' . $neworderinfo['expressprcie']]; |
|||
} |
|||
$data2 = [ |
|||
['Type' => 'String' , 'Content' => '实付金额:' . self::$orderInfo['price']] , |
|||
['Type' => 'String' , 'Content' => '--------------------------------'] , |
|||
['Type' => 'String' , 'Content' => '会员级别:' . self::$userInfo['lv']] , |
|||
['Type' => 'String' , 'Content' => '会员姓名:' . self::$userInfo['nickname']] , |
|||
['Type' => 'String' , 'Content' => '打印时间:' . date("Y-m-d H:i:s" , self::$timeStamp)] , |
|||
['Type' => 'String' , 'Content' => '--------------------------------'] , |
|||
['Type' => 'String' , 'Content' => ' 请妥善保管好购物凭证 '] , |
|||
['Type' => 'String' , 'Content' => ' 谢谢惠顾 '] , |
|||
]; |
|||
$data = array_merge_recursive($data1,$data2); |
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 支付方式 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 9:41 |
|||
* @param $type |
|||
* @return string |
|||
*/ |
|||
protected static function getPayType(){ |
|||
switch (self::$orderInfo['paytype']){ |
|||
case 1:$typeName = '余额';break;//余额 |
|||
case 2:$typeName = '微信';break;//微信 |
|||
case 3:$typeName = '支付宝';break;//支付宝 |
|||
} |
|||
|
|||
return $typeName.'支付'; |
|||
} |
|||
/** |
|||
* Comment: 获取支付项目 |
|||
* Author: zzw |
|||
* Date: 2020/4/8 18:22 |
|||
* @param $type |
|||
* @return string |
|||
*/ |
|||
protected static function getPayProject(){ |
|||
Util::wl_log('printing222' , PATH_MODULE . "log/" ,self::$orderInfo, '打印推送消息 —— 错误记录'); //写入日志记录 |
|||
switch (self::$orderInfo['payfor']) { |
|||
case 'Applydis': |
|||
$title = '开通分销商'; |
|||
break;//开通分销商 |
|||
case 'BargainOrder': |
|||
$title = pdo_getcolumn(PDO_NAME."bargain_activity",['id'=>self::$orderInfo['goods_id']],'name'); |
|||
break;//砍价商品购买 |
|||
case 'Bond': |
|||
$title = '认证保证金缴纳'; |
|||
break;//认证保证金缴纳 |
|||
case 'Charge': |
|||
$title = '付费入驻'; |
|||
break;//付费入驻 |
|||
case 'CitycardOrder': |
|||
$title = '同城名片支付'; |
|||
break;//同城名片支付 |
|||
case 'consumOrder': |
|||
$title = pdo_getcolumn(PDO_NAME."consumption_goods",['id'=>self::$orderInfo['goods_id']],'title'); |
|||
break;//积分商品购买 |
|||
case 'Couponsharge': |
|||
$title = pdo_getcolumn(PDO_NAME."couponlist",['id'=>self::$orderInfo['goods_id']],'title');; |
|||
break;//卡卷购买 |
|||
case 'Fightsharge': |
|||
$title = pdo_getcolumn(PDO_NAME."fightgroup_goods",['id'=>self::$orderInfo['goods_id']],'name');; |
|||
break;//拼团商品购买 |
|||
case 'GrouponOrder': |
|||
$title = pdo_getcolumn(PDO_NAME."groupon_activity",['id'=>self::$orderInfo['goods_id']],'name');; |
|||
break;//团购商品购买 |
|||
case 'halfcard': |
|||
$title = '一卡通开通/续费'; |
|||
break;//一卡通开通/续费 |
|||
case 'payonline': |
|||
$title = '在线买单'; |
|||
break;//在线买单 |
|||
case 'pocketfabusharge': |
|||
$title = '帖子付费项目'; |
|||
break;//帖子付费项目 |
|||
case 'RushOrder': |
|||
$title = pdo_getcolumn(PDO_NAME."rush_activity",['id'=>self::$orderInfo['goods_id']],'name');; |
|||
break;//抢购商品购买 |
|||
case 'TaxipayOrder': |
|||
$title = '出租车在线买单'; |
|||
break;//出租车在线买单 |
|||
case 'DeliveryOrder': |
|||
$orderno = self::$orderInfo['orderno']; |
|||
$smallorders = pdo_fetchall("SELECT gid,money,num,specid FROM ".tablename('wlmerchant_delivery_order')."WHERE tid = {$orderno} ORDER BY price DESC"); |
|||
foreach ($smallorders as $ke => &$orr){ |
|||
$goods = pdo_get('wlmerchant_delivery_activity',array('id' => $orr['gid']),array('name')); |
|||
$orr['name'] = $goods['name']; |
|||
if($orr['specid']>0){ |
|||
$specname = pdo_getcolumn(PDO_NAME.'delivery_spec',array('id'=>$orr['specid']),'name'); |
|||
$orr['name'] .= '/'.$specname; |
|||
} |
|||
$title[] = $orr['name'].' X'.$orr['num']; |
|||
} |
|||
break;//同城配送 |
|||
} |
|||
return $title; |
|||
} |
|||
/** |
|||
* Comment: 发送请求 |
|||
* Author: zzw |
|||
* Date: 2020/4/2 18:23 |
|||
* @param $url |
|||
* @param $data |
|||
* @return bool|string |
|||
*/ |
|||
protected static function postData($url, $data) { |
|||
$ch = curl_init (); |
|||
$timeout = 300; // 设定超时时间 |
|||
curl_setopt ( $ch, CURLOPT_URL, $url ); |
|||
curl_setopt ( $ch, CURLOPT_POST, 1 ); |
|||
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); |
|||
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); |
|||
curl_setopt ( $ch, CURLOPT_CONNECTTIMEOUT, $timeout ); |
|||
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false ); |
|||
$handles = curl_exec ( $ch ); |
|||
|
|||
$httpCode = curl_getinfo ( $ch, CURLINFO_HTTP_CODE ); |
|||
if ($httpCode != 200) { |
|||
if ($httpCode == 0) { |
|||
return "{\"status\":-1,\"message\":\"网络连接失败!\"}"; |
|||
} else { |
|||
return "{\"status\":-1,\"message\":\"网络或者服务器出现异常,HTTP返回状态码" . $httpCode . "\"}"; |
|||
} |
|||
} |
|||
curl_close ( $ch ); |
|||
return $handles; |
|||
} |
|||
|
|||
|
|||
|
|||
/** |
|||
* Comment: 获取打印配置信息 |
|||
* Author: zzw |
|||
* Date: 2020/4/3 14:02 |
|||
* @param $tid |
|||
* @return false|mixed|string |
|||
*/ |
|||
public static function getPrintingData($tid){ |
|||
global $_W; |
|||
#1、信息获取 |
|||
self::$tid = $tid; |
|||
self::$timeStamp = time(); |
|||
self::getOrder();//订单信息获取 |
|||
self::getStore();//商户信息获取 |
|||
self::getUser();//用户信息获取 |
|||
$data = self::getData();//获取打印设置信息 |
|||
return $data; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,327 @@ |
|||
<?php |
|||
/** |
|||
* 订单退款模型/商户提现打款模型/代理商提现打款模型 |
|||
*/ |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
use Yansongda\Pay\Pay as YanSongDa; |
|||
class Refund{ |
|||
protected static $orderNo ,//订单号 |
|||
$orderInfo ,//订单信息 |
|||
$source ,//渠道信息:1=公众号(默认);2=h5;3=小程序 |
|||
$type ,//支付方式:1=余额;2=微信;3=支付宝;4=货到付款 |
|||
$key ,//由渠道信息和支付方式拼接获得 |
|||
$settingInfo ,//支付设置信息 |
|||
$configInfo ,//支付配置信息 |
|||
$payNotify ,//异步通知地址 |
|||
$payReturn ,//跳转地址 |
|||
$refundPrice ,//退款的金额 |
|||
$blendcredit ,//退款的余额 |
|||
$payLogPath = PATH_MODULE."payment/",//支付异步通知日志地址 |
|||
$dd; |
|||
|
|||
/** |
|||
* Comment: 申请退款并且进行信息的初始化 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 17:36 |
|||
* @param $order_no |
|||
* @param int $price |
|||
* @return array|bool|string |
|||
*/ |
|||
public static function refundInit($order_no,$price = -1,$blendcredit = 0){ |
|||
self::$orderNo = $order_no; |
|||
self::$refundPrice = $price; |
|||
self::$blendcredit = $blendcredit; |
|||
#1、订单信息获取 |
|||
$res = self::getOrderInfo(); |
|||
if ($res) return $res; |
|||
#1、拼接渠道信息和支付方式 获得key信息 1_credit |
|||
//渠道信息:1=公众号(默认);2=h5;3=小程序 |
|||
//支付方式:1=余额;2=微信;3=支付宝;4=货到付款 5=云收单 |
|||
if($price < 0.01 && $blendcredit > 0){ |
|||
self::$refundPrice = $blendcredit; |
|||
self::$orderInfo['type'] = 1; |
|||
} |
|||
self::$key = self::$orderInfo['source'].'_'.self::$orderInfo['type']; |
|||
#1、支付设置信息获取 |
|||
self::getSettingInfo(); |
|||
#1、调用对应的退款接口 |
|||
switch (self::$key){ |
|||
case '1_1': case '2_1': case '3_1': |
|||
$res = self::balance(); |
|||
break;//余额退款(所有渠道) |
|||
case '1_2': case '2_2':case '3_2': |
|||
//self::$payNotify = PAY_PATH."WeChatRefund.php"; |
|||
//self::$payReturn = ''; |
|||
self::weChatConfig(); |
|||
$res = self::weChat_weChat(); |
|||
if(self::$blendcredit > 0 && $res['error'] > 0){ |
|||
Member::credit_update_credit2(self::$orderInfo['mid'],self::$blendcredit,'订单['.self::$orderNo.']退款'); |
|||
} |
|||
break;//公众号 - 微信退款 || H5 - 微信退款 |
|||
case '1_3': case '2_3': |
|||
self::$payNotify = PAY_PATH."AlipayRefund.php"; |
|||
self::$payReturn = ''; |
|||
self::aliPayConfig(); |
|||
$res = self::weChat_aliPay(); |
|||
break;//公众号 - 支付宝退款 || H5 - 支付宝退款 |
|||
case '1_5': |
|||
self::yunWeChatConfig(); |
|||
$res = self::Yun_WeChat_WeChat(); |
|||
break;//公众号 - 云收单 |
|||
} |
|||
|
|||
return $res; |
|||
} |
|||
|
|||
/****** 退款接口 ******************************************************************************************************/ |
|||
/** |
|||
* Comment: 余额退款 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 16:07 |
|||
* @return array|bool |
|||
*/ |
|||
protected static function balance(){ |
|||
#2、余额退款,直接为用户添加余额即可 |
|||
Member::credit_update_credit2(self::$orderInfo['mid'],self::$refundPrice,'订单['.self::$orderNo.']退款'); |
|||
return ['error'=>1]; |
|||
} |
|||
/** |
|||
* Comment: 微信公众号|H5 - 微信退款 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 17:25 |
|||
* @return array |
|||
*/ |
|||
protected static function weChat_weChat(){ |
|||
#1、配置订单信息 |
|||
$order = [ |
|||
'out_trade_no' => self::$orderInfo['pay_order_no'] , |
|||
'out_refund_no' => 'R'.rand(0,9).self::$orderNo , |
|||
'total_fee' => sprintf("%.0f",self::$orderInfo['fee'] * 100), |
|||
'refund_fee' => sprintf("%.0f",self::$refundPrice * 100), |
|||
'refund_desc' => '订单['.self::$orderNo.']退款' , |
|||
]; |
|||
#2、调用接口进行退款操作 |
|||
try { |
|||
yanSongDa::wechat(self::$configInfo)->refund($order); |
|||
return ['error'=>1]; |
|||
} catch (Exception $e) { |
|||
$emg = $e->getMessage(); |
|||
return ['error'=>0,'msg'=>$emg]; |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 微信公众号|H5 - 支付宝退款 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 17:35 |
|||
* @return array |
|||
*/ |
|||
protected static function weChat_aliPay(){ |
|||
#1、获取支付宝订单信息 |
|||
$order = [ |
|||
'out_trade_no' => self::$orderInfo['pay_order_no'], |
|||
'refund_amount' => self::$refundPrice, |
|||
'out_request_no' => rand(100,999).time(), |
|||
]; |
|||
#2、调用接口进行退款操作 |
|||
try { |
|||
yanSongDa::alipay(self::$configInfo)->refund($order); |
|||
return ['error'=>1]; |
|||
} catch (Exception $e) { |
|||
$emg = $e->getMessage(); |
|||
//忽略签名错误 |
|||
if($emg == 'INVALID_SIGN: Alipay Sign Verify FAILED'){ |
|||
return ['error'=>1]; |
|||
}else{ |
|||
return ['error'=>0,'msg'=>$emg]; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
/****** 配置信息获取 **************************************************************************************************/ |
|||
/** |
|||
* Comment: 支付宝配置信息获取 |
|||
* Author: zzw |
|||
* Date: 2019/8/29 10:30 |
|||
* @return array |
|||
*/ |
|||
protected static function aliPayConfig(){ |
|||
self::$configInfo = [ |
|||
'app_id' => trim(self::$settingInfo['ali_app_id']), |
|||
'notify_url' => trim(self::$payNotify), |
|||
'return_url' => trim(self::$payReturn), |
|||
'ali_public_key' => trim(self::$settingInfo['ali_public_key']), |
|||
'private_key' => trim(self::$settingInfo['app_private_key']), |
|||
]; |
|||
} |
|||
/** |
|||
* Comment: 微信配置信息获取 |
|||
* Author: zzw |
|||
* Date: 2019/9/2 15:00 |
|||
*/ |
|||
protected static function weChatConfig(){ |
|||
$filePath = PATH_ATTACHMENT . "public_file/" . MODULE_NAME . "/"; |
|||
if(self::$settingInfo['shop_type'] == 2){ |
|||
//子商户支付 |
|||
self::$configInfo = [ |
|||
'appid' => trim(self::$settingInfo['sub_up_app_id']) , // APP APPID |
|||
'app_id' => trim(self::$settingInfo['sub_up_app_id']) , // 公众号 APPID |
|||
'miniapp_id' => trim(self::$settingInfo['sub_up_app_id']) , // 小程序 APPID |
|||
'sub_appid' => trim(self::$settingInfo['app_id']) , // 子商户 APP APPID |
|||
'sub_app_id' => trim(self::$settingInfo['app_id']) , // 子商户 公众号 APPID |
|||
'sub_miniapp_id' => trim(self::$settingInfo['app_id']) , // 子商户 小程序 APPID |
|||
'mch_id' => trim(self::$settingInfo['shop_number']) , |
|||
'sub_mch_id' => trim(self::$settingInfo['sub_shop_number']) , // 子商户商户号 |
|||
'key' => trim(self::$settingInfo['secret_key']) ,//secret_key sub_secret_key |
|||
'notify_url' => trim(self::$payNotify) , |
|||
'cert_client' => trim($filePath . self::$settingInfo['cert_certificate']) , // optional, 退款,红包等情况时需要用到 |
|||
'cert_key' => trim($filePath . self::$settingInfo['key_certificate']) ,// optional, 退款,红包等情况时需要用到 |
|||
'mode' => 'service' , |
|||
]; |
|||
//是否开启子商户企业付款 |
|||
/*if (self::$setting['sub_enterprise_payment'] == 2) { |
|||
self::$payConfig['key'] = trim(self::$setting['sub_secret_key']); |
|||
self::$payConfig['cert_client'] = trim(self::$setting['sub_cert_certificate']); |
|||
self::$payConfig['cert_key'] = trim(self::$setting['sub_key_certificate']); |
|||
}*/ |
|||
}else{ |
|||
//一般支付 |
|||
self::$configInfo = [ |
|||
'appid' => trim(self::$settingInfo['app_id']) , // APP APPID |
|||
'app_id' => trim(self::$settingInfo['app_id']) , // 公众号 APPID |
|||
'miniapp_id' => trim(self::$settingInfo['app_id']) , // 小程序 APPID |
|||
'mch_id' => trim(self::$settingInfo['shop_number']) , |
|||
'key' => trim(self::$settingInfo['secret_key']) , |
|||
'notify_url' => trim(self::$payNotify) , |
|||
'cert_client' => trim($filePath . self::$settingInfo['cert_certificate']) , // optional, 退款,红包等情况时需要用到 |
|||
'cert_key' => trim($filePath . self::$settingInfo['key_certificate']) ,// optional, 退款,红包等情况时需要用到 |
|||
]; |
|||
} |
|||
} |
|||
|
|||
protected static function yunWeChatConfig(){ |
|||
//云收单 |
|||
$yun_signIn = Payment::yunSignIn(self::$settingInfo['yun_merchantNo'],self::$settingInfo['yun_terminalNo']); |
|||
self::$configInfo = [ |
|||
'itpOrderId' => self::$orderInfo['transaction_id'], |
|||
'merchantNo' => self::$settingInfo['yun_merchantNo'], |
|||
'terminalNo' => self::$settingInfo['yun_terminalNo'], |
|||
'batchNo' => $yun_signIn['batchNo'], |
|||
'traceNo' => $yun_signIn['traceNo'], |
|||
'mchtRefundNo' => 'R'.rand(0,9).self::$orderNo, |
|||
'refundAmount' => sprintf("%.0f",self::$refundPrice * 100), |
|||
'nonceStr' => random(16) |
|||
]; |
|||
} |
|||
|
|||
|
|||
/****** 公共方法 ******************************************************************************************************/ |
|||
/** |
|||
* Comment: 获取订单信息 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 15:06 |
|||
*/ |
|||
protected static function getOrderInfo(){ |
|||
#1、获取订单信息 |
|||
self::$orderInfo = pdo_get(PDO_NAME."paylogvfour",['tid'=>self::$orderNo] |
|||
,['transaction_id','source','mid','tid','fee','status','plugin','type','pay_order_no','blendcredit','batchNo','traceNo']); |
|||
#2、判断当前订单是否符合退款操作 |
|||
if(!self::$orderInfo){ |
|||
self::$orderInfo = pdo_get(PDO_NAME."paylog",['tid'=>self::$orderNo],['transaction_id','source','mid','tid','fee','status','plugin','type','pay_order_no']); |
|||
} |
|||
if(!self::$orderInfo) return array('error'=>0,'msg'=>'订单不存在'); |
|||
if(self::$orderInfo['status'] == 0) return array('error'=>0,'msg'=>'订单未支付,不可退款'); |
|||
if(self::$orderInfo['plugin'] == 'Rush'){ |
|||
self::$orderInfo['sid'] = pdo_getcolumn(PDO_NAME.'rush_order',array('orderno' => self::$orderNo ),'sid'); |
|||
}else { |
|||
self::$orderInfo['sid'] = pdo_getcolumn(PDO_NAME.'order',array('orderno' => self::$orderNo ),'sid'); |
|||
} |
|||
#3、同订单信息获取其他基本信息 |
|||
self::$source = self::$orderInfo['source']; |
|||
self::$type = self::$orderInfo['type']; |
|||
if(self::$orderInfo['blendcredit'] > 0){ |
|||
self::$orderInfo['fee'] = sprintf("%.2f",self::$orderInfo['fee'] - self::$orderInfo['blendcredit']); |
|||
} |
|||
if(self::$refundPrice <= 0) self::$refundPrice = self::$orderInfo['fee']; |
|||
//判断云收单 |
|||
if(!empty(self::$orderInfo['batchNo'])){ |
|||
self::$orderInfo['type'] = 5; |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 获取当前订单支付方式对应的支付设置信息 |
|||
* Author: zzw |
|||
* Date: 2019/9/28 15:40 |
|||
*/ |
|||
protected static function getSettingInfo(){ |
|||
global $_W; |
|||
#1、通过key值获取 |
|||
$set = Setting::wlsetting_read("payment_set"); |
|||
$cashset = Setting::wlsetting_read("cashset"); |
|||
switch (self::$key){ |
|||
case '1_2': |
|||
if($cashset['allocationtype'] == 1){ |
|||
$id = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>self::$orderInfo['sid']),'wxallid'); |
|||
} |
|||
if(empty($id)){ |
|||
$id = $set['wechat']['wechat']; |
|||
} |
|||
break;//公众号 - 微信支付配置信息 |
|||
case '1_3': |
|||
$id = $set['wechat']['alipay']; |
|||
break;//公众号 - 支付宝配置信息 |
|||
case '2_2': |
|||
$id = $set['h5']['wechat']; |
|||
break;//H5 - 微信支付配置信息 |
|||
case '2_3': |
|||
$id = $set['h5']['alipay']; |
|||
break;//H5 - 支付宝配置信息 |
|||
case '3_2': |
|||
if($cashset['allocationtype'] == 1){ |
|||
$id = pdo_getcolumn(PDO_NAME.'merchantdata',array('id'=>self::$orderInfo['sid']),'appallid'); |
|||
} |
|||
if(empty($id)){ |
|||
$id = $set['wxapp']['wechat']; |
|||
} |
|||
break;//小程序 - 微信支付 |
|||
case '1_5': |
|||
$id = $set['wechat']['yunpay']; |
|||
break;//公众号 - 云收单 |
|||
} |
|||
#2、获取设置信息数据 |
|||
self::$settingInfo = json_decode(pdo_getcolumn(PDO_NAME."payment",['id'=>$id],'param'),true); |
|||
#3、获取对应渠道的appid |
|||
switch (self::$type){ |
|||
case 2: |
|||
if(self::$source == 1){ |
|||
$account = $_W['account'] ? : uni_fetch($_W['uniacid']); |
|||
self::$settingInfo['app_id'] = Util::object_array($account)['key'];//公众号、H5 |
|||
}else{ |
|||
self::$settingInfo['app_id'] = Setting::wlsetting_read('wxapp_config')['appid'];//小程序 |
|||
} |
|||
break;//微信 |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Comment: 微信公众号 —— 云收单微信支付 |
|||
* Author: wlf |
|||
* Date: 2021/07/22 16:09 |
|||
* @return array |
|||
*/ |
|||
protected static function Yun_WeChat_WeChat(){ |
|||
$wechatUrl = 'https://epos.ahrcu.com:3443/cposp/pay/refund'; |
|||
$wechatData = self::$configInfo; |
|||
$wechatData['sign'] = Payment::getYunSign($wechatData,self::$settingInfo['yun_KEY']); |
|||
$wechatData = json_encode($wechatData); |
|||
$refundInfo = curlPostRequest($wechatUrl,$wechatData,["Content-type: application/json;charset='utf-8'"]); |
|||
if($refundInfo['refundStatus'] != '01'){ |
|||
Util::wl_log('160PayApi.log',PATH_DATA,$refundInfo); //写入异步日志记录 |
|||
return ['error'=>0,'msg'=>$refundInfo['errorDesc']]; |
|||
}else{ |
|||
return ['error'=>1]; |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,628 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
/** |
|||
* 用户权益 / 权益启用 / 权益 |
|||
*/ |
|||
class Rights |
|||
{ |
|||
protected static $tableName = PDO_NAME . 'rights'; |
|||
|
|||
public static $dateUnit = [ |
|||
1 => '天', /* 2 => '周',*/ 3 => '月'/*, 4 => '年'*/ |
|||
]; |
|||
|
|||
public static $graduatedSchool = [6 => '大专',1 => '统招本科', 2 => '重点院校', 3 => '双一流', 4 => '211', 5 => '985']; |
|||
|
|||
public static $experience = [1 => '在校干部', 2 => '实习经验']; |
|||
|
|||
public static $levelList = ['基础配置']; |
|||
|
|||
public static $amountUnit = [1 => '个', 2 => '份' , 3 => '次']; |
|||
|
|||
public static $unit = [1 => '个', 2 => '份' , 3 => '次', 4 => '天']; |
|||
|
|||
public static $calculateMethod = [1 => '天', 2 => '个']; |
|||
|
|||
public static $monthData = [30 => '一个月', 90 => '三个月', 180 => '六个月' , 365 => '一年']; |
|||
|
|||
public static $dayData = [10 => '10天', 30 => '30天', 50 => '50天' , 100 => '100天']; |
|||
|
|||
public static $numData = [10 => '10次', 30 => '30次', 50 => '50次' , 100 => '100次']; |
|||
|
|||
public static $copyData = [10 => '10份', 30 => '30份', 50 => '50份' , 100 => '100份']; |
|||
|
|||
public static function dump($data,$is_die = true) { |
|||
echo "<pre>"; |
|||
var_dump($data); |
|||
if ($is_die) die; |
|||
} |
|||
|
|||
public static function getRightsBagAll () { |
|||
return pdo_getall(PDO_NAME . 'rights_bag',['status' => 1]); |
|||
} |
|||
|
|||
public static function getRightsList() { |
|||
return pdo_getall(self::$tableName,['status' => 1]); |
|||
} |
|||
|
|||
/** |
|||
* 权益合并显示列表 |
|||
* @return array |
|||
*/ |
|||
public static function getRightsMergeList() |
|||
{ |
|||
$list = []; |
|||
|
|||
$res = self::getRightsList(); |
|||
|
|||
foreach ($res as $row) { |
|||
|
|||
$base_rights = ''; |
|||
$vip_rights = ''; |
|||
$specRes = pdo_getall(PDO_NAME . 'rights_spec',['rightsid' => $row['id']]); |
|||
foreach ($specRes as $specRow) { |
|||
if ($specRow['rights_bagid'] == 1) { |
|||
$base_rights = self::getSpecInfo($specRow,$row['rights_type']); |
|||
} elseif ($specRow['rights_bagid'] == 2) { |
|||
$vip_rights = self::getSpecInfo($specRow,$row['rights_type']); |
|||
} |
|||
} |
|||
$list[] = [ |
|||
'rights_type' => $row['rights_type'], |
|||
'base_rights' => $base_rights, |
|||
'vip_rights' => $vip_rights |
|||
]; |
|||
} |
|||
|
|||
return $list; |
|||
} |
|||
|
|||
/** |
|||
* 获取规格信息 |
|||
* @param $item // 权益规格数据 |
|||
* @param $rights_type // 权益类型 |
|||
* @return string |
|||
*/ |
|||
protected static function getSpecInfo($item,$rights_type) { |
|||
$rights_str = ''; |
|||
|
|||
if ($item['amount'] > 0) { |
|||
$rights_str .= $item['amount'] . self::$amountUnit[$item['amount_unit']]; |
|||
} |
|||
if ($item['date_amount'] > 0) { |
|||
if (!empty($rights_str)) $rights_str .= '/'; |
|||
$rights_str .= $item['date_amount'] . self::$dateUnit[$item['date_unit']]; |
|||
} |
|||
|
|||
if ($rights_type == '精准人才卡' && !empty($rights_str) && $item['date_amount'] <= 0) { |
|||
$rights_str .= '/简历'; |
|||
} |
|||
return $rights_str; |
|||
} |
|||
|
|||
/** |
|||
* 获取用户权益使用信息 |
|||
* @param $mid |
|||
* @return array |
|||
*/ |
|||
public static function getMemberRightsUsageInfo($mid) { |
|||
|
|||
$diyData = []; |
|||
|
|||
$rightsRes = self::getRightsList(); |
|||
|
|||
foreach ($rightsRes as $rightsRow) { |
|||
|
|||
$memberRightsWhere = ['mid' => $mid,'status' => 1,'rightsid' => $rightsRow['id']]; |
|||
$memberRights = pdo_get(PDO_NAME .'member_rights',$memberRightsWhere); |
|||
$use_amount = $memberRights['use_amount'] ?: 0; |
|||
$diyData[] = [ |
|||
'name' => $rightsRow['rights_type'], |
|||
'total_amount' => $memberRights['total_amount'] ?: 0, |
|||
'use_amount' => self::getUseAmount($rightsRow['id'],$memberRights['id'],$use_amount,$memberRights['total_amount']), |
|||
'unit' => self::$calculateMethod[$rightsRow['calculate_method']], |
|||
'rights_id' => $rightsRow['id'] |
|||
]; |
|||
} |
|||
|
|||
# 特殊标题 |
|||
$arr = ['猎头服务', '视频号直播', '企业视频制作']; |
|||
foreach ($arr as $name) { |
|||
$diyData[] = [ |
|||
'name' => $name, |
|||
'total_amount' => '', |
|||
'use_amount' => '', |
|||
'unit' => '', |
|||
'rights_id' => '' |
|||
]; |
|||
} |
|||
|
|||
return $diyData; |
|||
} |
|||
|
|||
/** |
|||
* 获取剩余数量 |
|||
* @param $rightsid // 权益ID |
|||
* @param $member_rightsid // 用户权益ID |
|||
* @param $use_amount // 使用权益数量 |
|||
* @param $total_amount // 总权益数量 |
|||
* @return int|mixed |
|||
*/ |
|||
public static function getUseAmount($rightsid,$member_rightsid,$use_amount,$total_amount) { |
|||
if (!in_array($rightsid,[2,5])) return $total_amount - $use_amount; // 置顶权益和精准人才卡特殊处理 |
|||
$useTotalAmount = 0; |
|||
$rightsUse = pdo_getall(PDO_NAME . 'member_rights_use',['member_rightsid' => $member_rightsid],['use_total_amount']); |
|||
foreach ($rightsUse as $rightsUseValue) { |
|||
$useTotalAmount += $rightsUseValue['use_total_amount']; |
|||
} |
|||
return $total_amount - $useTotalAmount; |
|||
} |
|||
|
|||
/** |
|||
* 获取企业招聘岗位信息 |
|||
* @param $mid |
|||
* @return array |
|||
*/ |
|||
public static function getStoreRecruitInfo($mid) { |
|||
$data = []; |
|||
|
|||
$storeIdArr = []; |
|||
$storeUser = pdo_getall(PDO_NAME . 'merchantuser',['mid' => $mid],['storeid']); |
|||
foreach ($storeUser as $storeUserRow) { |
|||
$storeIdArr[] = $storeUserRow['storeid']; |
|||
} |
|||
|
|||
$recruit = pdo_getall(PDO_NAME . 'recruit_recruit',['release_sid' => $storeIdArr, 'status' => 4],['id','release_sid','title']); |
|||
foreach ($recruit as $recruit_row) { |
|||
$data[] = [ |
|||
'recruit_id' => $recruit_row['id'], |
|||
'recruit_title' => $recruit_row['title'] |
|||
]; |
|||
} |
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* 权益支付成功 生成用户权益 |
|||
* @param $mid |
|||
* @param $orderid // 订单id |
|||
* @param $orderData // 订单数据 |
|||
* @return void |
|||
*/ |
|||
public static function rightsPaySuccess($mid,$orderid, $orderData = array()) { |
|||
global $_W; |
|||
|
|||
if (empty($orderData)) { |
|||
$orderData = pdo_get(PDO_NAME . 'order',['id' => $orderid,'plugin' => 'rights']); |
|||
} |
|||
|
|||
if ($orderData) { |
|||
|
|||
$rightsid = $orderData['fkid']; // 权益id 或是 权益包id |
|||
$payfor = $orderData['payfor']; // rights-权益 rightsBag-权益包 |
|||
$num = $orderData['num']; // 购买数量 |
|||
|
|||
switch ($payfor) { |
|||
case 'rights': |
|||
|
|||
self::createMemberRights($_W['uniacid'],$rightsid,$mid,$num); |
|||
break; |
|||
case 'rightsBag': |
|||
|
|||
$rightsSpec = pdo_getall(PDO_NAME . 'rights_spec',['rights_bagid' => $rightsid]); |
|||
foreach ($rightsSpec as $row) { |
|||
if ($row['calculate_method'] == 1) { |
|||
$num = $row['date_amount']; |
|||
} elseif ($row['calculate_method'] == 2) { |
|||
$num = $row['amount']; |
|||
} |
|||
self::createMemberRights($_W['uniacid'],$row['rightsid'],$mid,$num,$rightsid); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 初始商家创建基础权益 |
|||
* @param $mid |
|||
* @param $uniacid |
|||
* @return string|void |
|||
*/ |
|||
public static function createBaseRights($mid,$uniacid) { |
|||
$queryExists = pdo_get(PDO_NAME . 'member_rights',['mid' => $mid]); |
|||
if ($queryExists) return ''; |
|||
$rightsBag = pdo_getall(PDO_NAME . 'rights_spec',['rights_bagid' => 1]); |
|||
foreach ($rightsBag as $value) { |
|||
if ($value['rightsid'] == 3) continue; |
|||
if ($value['amount'] > 0) { |
|||
self::createMemberRights($uniacid,$value['rightsid'],$mid,$value['amount'],1); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 创建|修改 用户权益 |
|||
* @param $uniacid |
|||
* @param $rightsid |
|||
* @param $mid |
|||
* @param $num |
|||
* @param $rights_bagid |
|||
* @return void |
|||
*/ |
|||
protected static function createMemberRights($uniacid,$rightsid,$mid,$num,$rights_bagid = 0) { |
|||
$memberRightsWhere = ['rightsid' => $rightsid,'mid' => $mid,'status' => 1]; |
|||
$memberRights = pdo_get(PDO_NAME . 'member_rights',$memberRightsWhere,['id','total_amount']); |
|||
$member_rightsid = $memberRights['id']; |
|||
if ($memberRights) { |
|||
$updateData = ['total_amount' => $memberRights['total_amount'] + $num]; |
|||
pdo_update(PDO_NAME . 'member_rights',$updateData,['id' => $member_rightsid]); |
|||
} else { |
|||
$insertData = [ |
|||
'uniacid' => $uniacid, |
|||
'rightsid' => $rightsid, |
|||
'rights_bagid' => $rights_bagid, |
|||
'mid' => $mid, |
|||
'total_amount' => $num, |
|||
'create_time' => time(), |
|||
]; |
|||
pdo_insert(PDO_NAME . 'member_rights',$insertData); |
|||
$member_rightsid = pdo_insertid(); |
|||
} |
|||
if (in_array($rightsid,[1,3,4])) { |
|||
$relation_type = pdo_getcolumn(self::$tableName,['id' => $rightsid],'relation_type'); |
|||
self::saveMemberRightsUse($rightsid,$member_rightsid,$num,0,$relation_type); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 获取权益商品名称 |
|||
* @param $fkid |
|||
* @param $payfor |
|||
* @return mixed|string |
|||
*/ |
|||
public static function getRightsGoodname($fkid,$payfor) |
|||
{ |
|||
if (empty($fkid)) return ''; |
|||
if (empty($payfor) || !in_array($payfor,['rights','rightsBag'])) return ''; |
|||
|
|||
if ($payfor == 'rights') { |
|||
$rights = pdo_get(self::$tableName,['id' => $fkid],['rights_type']); |
|||
return $rights['rights_type']; |
|||
} elseif ($payfor == 'rightsBag') { |
|||
$rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $fkid],['title']); |
|||
return $rightsBag['title']; |
|||
} |
|||
return ''; |
|||
} |
|||
|
|||
/** |
|||
* 创建|追加 用户使用权益记录 |
|||
* @param $rightsid // 权益id |
|||
* @param $member_rightsid // 用户权益id |
|||
* @param $num // 使用数量 |
|||
* @param $relation_id // 关联id |
|||
* @param $relation_type // 关联类型 ad_exposure=广告曝光 recruit_top=招聘置顶 chat=畅聊 recruit_bout=招聘次数 recruit_resume=精准人才 |
|||
* @param $data |
|||
* @return array|bool[] |
|||
*/ |
|||
public static function saveMemberRightsUse($rightsid,$member_rightsid,$num,$relation_id,$relation_type = 'recruit_top',$data = []) { |
|||
global $_W; |
|||
|
|||
$rightsUseWhere = [ |
|||
'rightsid' => $rightsid, |
|||
'member_rightsid' => $member_rightsid, |
|||
'status' => [0,1], |
|||
'relation_id' => $relation_id, |
|||
'relation_type' => $relation_type |
|||
]; |
|||
$rightsUse = pdo_get(PDO_NAME . 'member_rights_use',$rightsUseWhere); |
|||
|
|||
if ($rightsUse) { |
|||
|
|||
$updateArr = ['use_total_amount' => $rightsUse['use_total_amount'] + $num]; |
|||
$updateRes = pdo_update(PDO_NAME . 'member_rights_use',$updateArr,['id' => $rightsUse['id']]); |
|||
if (!$updateRes) return ['status' => false,'msg' => '使用失败']; |
|||
} else { |
|||
|
|||
$insertArr = [ |
|||
'uniacid' => $_W['uniacid'], |
|||
'member_rightsid' => $member_rightsid, |
|||
'rightsid' => $rightsid, |
|||
'relation_type' => $relation_type, |
|||
'relation_id' => $relation_id, |
|||
'use_total_amount' => $num, |
|||
'filter' => serialize($data), |
|||
'create_time' => time() |
|||
]; |
|||
|
|||
$insertRes = pdo_insert(PDO_NAME . 'member_rights_use',$insertArr); |
|||
if (!$insertRes) return ['status' => false,'msg' => '使用失败']; |
|||
} |
|||
|
|||
return ['status' => true]; |
|||
} |
|||
|
|||
/** |
|||
* 获取用户权益 |
|||
* @param $mid |
|||
* @param $rightsid |
|||
* @return false|mixed |
|||
*/ |
|||
public static function getMemberRights($mid,$rightsid) { |
|||
$memberRightsSql = 'select * from ims_' . PDO_NAME . "member_rights where `mid` = '{$mid}' " |
|||
." and `rightsid` = '{$rightsid}' order by id desc limit 1"; |
|||
return pdo_fetch($memberRightsSql); |
|||
} |
|||
|
|||
/** |
|||
* 使用权益 |
|||
* @param $rightsid |
|||
* @param $mid |
|||
* @param $relation_id |
|||
* @param $relation_type |
|||
* @param $amount |
|||
* @return array|bool[]|void |
|||
*/ |
|||
public static function useMemberRights($rightsid,$mid,$relation_id = 0,$relation_type = 'recruit_bout',$amount = 1) { |
|||
|
|||
// 只限制商家,企业身份的用户 |
|||
$member = pdo_get(PDO_NAME . 'member',['id' => $mid],['identity_id']); |
|||
if (!in_array($member['identity_id'],[4,5])) return ['status' => true]; |
|||
|
|||
$rights = pdo_get(self::$tableName,['id' => $rightsid],['rights_type']); |
|||
|
|||
$isBuyStr = self::isBuyRights($mid,$rightsid); |
|||
$memberRights = self::getMemberRights($mid,$rightsid); |
|||
$rights_type = $rights['rights_type']; |
|||
if (strpos($rights_type,'权益') === false) $rights_type .= '权益'; |
|||
if (!$memberRights) return ['status' => false, 'msg' => "您未开通: {$rights_type},请前往购买后使用"]; |
|||
if ($memberRights['status'] == 0) return ['status' => false, 'msg' => $isBuyStr."{$rights_type}已用完,请前往购买后使用"]; |
|||
if ($memberRights['use_amount'] >= $memberRights['total_amount']) return ['status' => false, 'msg' => $isBuyStr."{$rights_type}已用完,请前往购买后使用"]; |
|||
$member_rightsid = $memberRights['id']; |
|||
|
|||
$rightsUseWhere = [ |
|||
'rightsid' => $rightsid, |
|||
'member_rightsid' => $member_rightsid, |
|||
'relation_id' => $relation_id, |
|||
'relation_type' => $relation_type, |
|||
'status' => [0,1] |
|||
]; |
|||
$rightsUse = pdo_get(PDO_NAME . 'member_rights_use',$rightsUseWhere); |
|||
$rights_useid = $rightsUse['id']; |
|||
if (!$rightsUse) return ['status' => false, 'msg' => "{$rights_type},购买的使用次数已全部使用"]; |
|||
if ($rightsUse['use_amount'] >= $rightsUse['use_total_amount']) return ['status' => false, 'msg' => "{$rights_type},购买的使用次数已全部使用"]; |
|||
|
|||
$use_amount = $rightsUse['use_amount'] + $amount; |
|||
if ($use_amount > $rightsUse['use_total_amount']) return ['status' => false, 'msg' => "{$rights_type},使用超出设定使用次数"]; |
|||
|
|||
// 扣减次数(子) |
|||
$updateData = ['use_amount' => $use_amount]; |
|||
if ($rightsUse['status'] == 0) { |
|||
$updateData['status'] = 1; |
|||
$updateData['start_time'] = time(); |
|||
} |
|||
$updateRes = pdo_update(PDO_NAME . 'member_rights_use',$updateData,['id' => $rights_useid]); |
|||
if (!$updateRes) return ['status' => false, 'msg' => "系统错误"]; |
|||
|
|||
$memberRightsUpData = ['use_amount' => $memberRights['use_amount'] + $amount]; |
|||
$updateRes = pdo_update(PDO_NAME . 'member_rights',$memberRightsUpData,['id' => $member_rightsid]); |
|||
if (!$updateRes) return ['status' => false, 'msg' => "系统错误"]; |
|||
|
|||
// 同步判断是否完结 |
|||
self::syncMemberRightsStatus($member_rightsid,$rights_useid); |
|||
|
|||
return ['status' => true]; |
|||
} |
|||
|
|||
/** |
|||
* 判断用户是否购买过该权益 |
|||
* @param $mid |
|||
* @param $rightsid |
|||
* @return string |
|||
* @author whj |
|||
* @date 2023-08-14 15:22 |
|||
*/ |
|||
protected static function isBuyRights($mid,$rightsid) |
|||
{ |
|||
# 是否购买过权益包 |
|||
$orderWhere1 = ['mid' => $mid, 'fkid' => 2,'payfor' => 'rightsBag','plugin' => 'rights','status' => 3]; |
|||
$order1 = pdo_get(PDO_NAME . 'order',$orderWhere1); |
|||
if ($order1) return '购买的'; |
|||
# 是否有单独购买过 |
|||
$orderWhere2 = ['mid' => $mid, 'fkid' => $rightsid,'payfor' => 'rights','plugin' => 'rights','status' => 3]; |
|||
$order2 = pdo_get(PDO_NAME . 'order',$orderWhere2); |
|||
return $order2 ? '购买的' : '免费的'; |
|||
} |
|||
|
|||
/** |
|||
* 同步修改用户权益状态,判断权益是否全部完成 |
|||
* @param $member_rightsid |
|||
* @param $rights_useid |
|||
* @return void |
|||
*/ |
|||
protected static function syncMemberRightsStatus($member_rightsid,$rights_useid) |
|||
{ |
|||
$rightsUse = pdo_get(PDO_NAME . 'member_rights_use',['id' => $rights_useid]); |
|||
// 判断用户权益是否使用完(子) |
|||
if ($rightsUse['use_amount'] >= $rightsUse['use_total_amount']) { |
|||
// 使用完自动完结 |
|||
$rightsUseData = ['status' => 2, 'end_time' => time()]; |
|||
// 判断用户全部权益是否使用完 |
|||
$rightsUseUpRes = pdo_update(PDO_NAME . 'member_rights_use',$rightsUseData,['id' => $rights_useid]); |
|||
if ($rightsUseUpRes) { |
|||
self::syncCancelTop($rightsUse['rightsid'],$rightsUse['relation_id']); |
|||
$memberRights = pdo_get(PDO_NAME . 'member_rights',['id' => $member_rightsid]); |
|||
if ( |
|||
$memberRights['use_amount'] >= $memberRights['total_amount'] |
|||
|| $rightsUse['use_amount'] >= $memberRights['total_amount'] |
|||
) { |
|||
// 完结用户总权益(父) |
|||
$memberRightsData = ['status' => 0]; |
|||
if ($rightsUse['use_amount'] >= $memberRights['total_amount']) { |
|||
$memberRightsData['use_amount'] = $rightsUse['use_amount']; |
|||
} |
|||
pdo_update(PDO_NAME . 'member_rights',$memberRightsData,['id' => $member_rightsid]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 招聘取消置顶 |
|||
* @param $rightsid // 权益id |
|||
* @param $recruit_id // 招聘信息id |
|||
* @return void |
|||
*/ |
|||
protected static function syncCancelTop($rightsid,$recruit_id) { |
|||
if ($rightsid == 2 && !empty($recruit_id)) { |
|||
pdo_update(PDO_NAME . 'recruit_recruit',['is_top' => 0],['id' => $recruit_id]); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 判断招聘是否可以置顶 rightsid = 2 |
|||
* @param $recruit_id |
|||
* @param $member_rightsid |
|||
* @param $memberRights |
|||
* @param $num |
|||
* @return int 0-未置顶不扣减 1-置顶扣减 2-置顶先不扣减 |
|||
*/ |
|||
public static function recruitIsTop($recruit_id,$member_rightsid,$memberRights = array(),$num = 1) |
|||
{ |
|||
// 判断招聘信息是否置顶 |
|||
$recruit = pdo_get(PDO_NAME . 'recruit_recruit',['id' => $recruit_id]); |
|||
if ($recruit['is_top'] == 1) return 1; |
|||
// 根据配置获取置顶个数 |
|||
if (empty($memberRights)) $memberRights = pdo_get(PDO_NAME .'member_rights',['id' => $member_rightsid]); |
|||
$rightsSpec = pdo_get(PDO_NAME . 'rights_spec',['rightsid' => $memberRights['rightsid'], 'rights_bagid' => $memberRights['rights_bagid']]); |
|||
if ($rightsSpec) { |
|||
$amount = 5; |
|||
$count = pdo_count(PDO_NAME . 'member_rights_use',['member_rightsid' => $member_rightsid,'status' => 1]); |
|||
if ($count >= $amount) return 0; |
|||
} |
|||
// 判断招聘信息置顶条数已满 |
|||
$topRecruit = pdo_getall(PDO_NAME . 'recruit_recruit',['cc_id' => $recruit['cc_id'],'is_top' => 1]); |
|||
$topCount = count($topRecruit); |
|||
if ($topCount >= 5) return 0; |
|||
// 修改招聘信息置顶 |
|||
$top_end_time = strtotime(date("Y-m-d 00:00:00",strtotime("+{$num} day"))); |
|||
$updateRes = pdo_update(PDO_NAME . 'recruit_recruit',['is_top' => 1,'top_end_time' => $top_end_time],['id' => $recruit_id]); |
|||
if (!$updateRes) return 0; |
|||
return 2; |
|||
} |
|||
|
|||
/** |
|||
* 判断是否有畅聊权益 rightsid = 3 |
|||
* @param $mid |
|||
* @return array|bool[] |
|||
*/ |
|||
public static function memberIsChat($mid) |
|||
{ |
|||
$rightsid = 3; |
|||
|
|||
// 只限制商家,企业身份的用户 |
|||
$identity_id = pdo_getcolumn(PDO_NAME . 'member',['id' => $mid],'identity_id'); |
|||
if (!in_array($identity_id,[4,5])) return ['status' => true]; |
|||
|
|||
$rights = pdo_get(self::$tableName,['id' => $rightsid],['rights_type']); |
|||
$isBuyStr = self::isBuyRights($mid,$rightsid); |
|||
$memberRights = self::getMemberRights($mid,$rightsid); |
|||
$rights_type = $rights['rights_type']; |
|||
if (!$memberRights) return ['status' => false, 'msg' => "您未开通: {$rights_type},请前往购买后使用"]; |
|||
if ($memberRights['status'] == 0) return ['status' => false, 'msg' => $isBuyStr."{$rights_type}已用完,请前往购买后使用"]; |
|||
|
|||
return ['status' => true]; |
|||
} |
|||
|
|||
/** |
|||
* Comment: 招聘信息支付回调处理 |
|||
* Date: 2021/1/8 17:04 |
|||
* @param $params |
|||
* @throws \GuzzleHttp\Exception\GuzzleException |
|||
*/ |
|||
public static function payRightsOrderNotify($params) { |
|||
global $_W; |
|||
//写入异步日志记录 |
|||
Util::wl_log('rights_notify', PATH_DATA . "rights/data/", $params); |
|||
$order = pdo_get(PDO_NAME."order",['orderno' => $params['tid']],['plugin','id','fkid','fightstatus','num','payfor','mid']); |
|||
//更新订单 |
|||
$data = array('status' => $params['result'] == 'success' ? 3 : 0); |
|||
$data['paytype'] = $params['type']; |
|||
if ($params['tag']['transaction_id']) $data['transid'] = $params['tag']['transaction_id']; |
|||
$data['paytime'] = TIMESTAMP; |
|||
$result = pdo_update(PDO_NAME . 'order', $data, array('id' => $order['id'])); |
|||
if ($result) { |
|||
Rights::rightsPaySuccess($order['mid'],$order['id'],$order); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 免费畅聊卡人数限制 |
|||
* @param $mid // 用户ID |
|||
* @param $send_type // 发送方类型(1=用户;2=商户) |
|||
* @return bool |
|||
*/ |
|||
public static function freeChatRights($mid,$send_type) |
|||
{ |
|||
$identity_id = pdo_getcolumn(PDO_NAME .'member',['id' => $mid],'identity_id'); |
|||
if (!in_array($identity_id,[4,5])) return true; |
|||
if ($send_type != 2) return true; |
|||
|
|||
$amount = pdo_getcolumn(PDO_NAME . 'rights_spec',['rightsid' => 3,'rights_bagid' => 1],'amount'); |
|||
if ($amount <= 0) return false; |
|||
|
|||
$storeid = pdo_getcolumn(PDO_NAME.'merchantuser',['mid' => $mid],'storeid'); |
|||
if (!$storeid) return false; |
|||
|
|||
$start_times = strtotime('today'); |
|||
|
|||
$imWhere = " send_id = {$storeid} AND send_type = {$send_type} AND create_time >= {$start_times} "; |
|||
$imCountRes = pdo_fetch("select COUNT(DISTINCT receive_id) AS num FROM ims_".PDO_NAME."im where {$imWhere}"); |
|||
$imCount = $imCountRes['num']; |
|||
|
|||
return $imCount < $amount ? true : false; |
|||
} |
|||
|
|||
/** |
|||
* 获取精准推送的简历 |
|||
* @param $recruit_id |
|||
* @return array |
|||
*/ |
|||
public static function getRightsRecruitResume($recruit_id) { |
|||
$resume_id = []; |
|||
$rightsUseWhere = ['rightsid' => 5,'relation_id' => $recruit_id]; |
|||
$rightsUse = pdo_getall(PDO_NAME . 'member_rights_use',$rightsUseWhere); |
|||
foreach ($rightsUse as $value) { |
|||
$filter = unserialize($value['filter']); |
|||
if (isset($filter['resume_id'])) { |
|||
$resume_id = array_merge($resume_id,$filter['resume_id']); |
|||
} |
|||
} |
|||
return array_unique($resume_id); |
|||
} |
|||
|
|||
/** |
|||
* 获取权益名称 |
|||
* @param $rightsfor |
|||
* @param $rightsid |
|||
* @return array |
|||
*/ |
|||
public static function getRightsInfo($rightsfor,$rightsid) |
|||
{ |
|||
if ($rightsfor == 'rights') { |
|||
$rights = pdo_get(PDO_NAME . 'rights',['id' => $rightsid]); |
|||
$goodsname = $rights['rights_type']; |
|||
$goodsprice = $rights['price']; |
|||
} else { |
|||
$rightsBag = pdo_get(PDO_NAME . 'rights_bag',['id' => $rightsid]); |
|||
$goodsname = $rightsBag['title']; |
|||
$goodsprice = $rightsBag['price']; |
|||
} |
|||
return [ |
|||
'name' => $goodsname, |
|||
'price' => $goodsprice, |
|||
]; |
|||
} |
|||
} |
|||
@ -0,0 +1,209 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Setting { |
|||
/* |
|||
* 读取所有设置 |
|||
*/ |
|||
static function wlsetting_load() { |
|||
global $_W; |
|||
$settings = Cache::getCache('setting', 'allset'); |
|||
|
|||
if (empty($settings) || !is_array($settings)) { |
|||
$setting = pdo_getall(PDO_NAME . 'setting', array('uniacid' => $_W['uniacid']), array('key', 'value')); |
|||
$settings_arr = array(); |
|||
if (is_array($setting)) { |
|||
foreach ($setting as $k => &$v) { |
|||
$settings_arr[$v['key']] = iunserializer($v['value']); |
|||
unset($setting[$k]); |
|||
} |
|||
$settings = $settings_arr; |
|||
} else { |
|||
$settings_arr = array(); |
|||
} |
|||
Cache::setCache('setting', 'allset', $settings_arr); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
/* |
|||
* 保存设置 |
|||
*/ |
|||
static function wlsetting_save($data, $key) { |
|||
global $_W; |
|||
if (empty($key)) { |
|||
return FALSE; |
|||
} |
|||
$record = array(); |
|||
$record['value'] = iserializer($data); |
|||
$exists = pdo_getcolumn(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => $_W['uniacid']), 'id'); |
|||
if ($exists) { |
|||
$return = pdo_update(PDO_NAME . 'setting', $record, array('key' => $key, 'uniacid' => $_W['uniacid'])); |
|||
} else { |
|||
$record['key'] = $key; |
|||
$record['uniacid'] = $_W['uniacid']; |
|||
$return = pdo_insert(PDO_NAME . 'setting', $record); |
|||
} |
|||
Cache::deleteCache('setting', 'allset'); |
|||
return $return; |
|||
} |
|||
|
|||
/* |
|||
* 读取单条设置 |
|||
*/ |
|||
static function wlsetting_read($key) { |
|||
global $_W; |
|||
$settings = pdo_get(PDO_NAME . 'setting', array('key' => $key, 'uniacid' => $_W['uniacid']), array('value')); |
|||
if (is_array($settings)) { |
|||
$settings = iunserializer($settings['value']); |
|||
} else { |
|||
$settings = array(); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
/* |
|||
* 读取所有设置 |
|||
*/ |
|||
static function agentsetting_load() { |
|||
global $_W; |
|||
$settings = Cache::getCache('setting', 'allagentset' . $_W['aid']); |
|||
if (empty($settings) || !is_array($settings)) { |
|||
$setting = pdo_getall(PDO_NAME . 'agentsetting', array('uniacid' => $_W['uniacid'], 'aid' => $_W['aid']), array('key', 'value')); |
|||
if (is_array($setting)) { |
|||
$settings_new = []; |
|||
foreach ($setting as $k => &$v) { |
|||
$settings_new[$v['key']] = iunserializer($v['value']); |
|||
unset($setting[$k]); |
|||
} |
|||
$settings = $settings_new; |
|||
} else { |
|||
$settings = array(); |
|||
} |
|||
|
|||
Cache::setCache('setting', 'allagentset' . $_W['aid'], $settings); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
/* |
|||
* 保存设置 |
|||
*/ |
|||
static function agentsetting_save($data, $key) { |
|||
global $_W; |
|||
if (empty($key)) { |
|||
return FALSE; |
|||
} |
|||
$record = array(); |
|||
$record['value'] = iserializer($data); |
|||
$exists = pdo_getcolumn(PDO_NAME . 'agentsetting', array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid']), 'id'); |
|||
if ($exists) { |
|||
$return = pdo_update(PDO_NAME . 'agentsetting', $record, array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $_W['aid'])); |
|||
} else { |
|||
$record['key'] = $key; |
|||
$record['uniacid'] = $_W['uniacid']; |
|||
$record['aid'] = $_W['aid']; |
|||
$return = pdo_insert(PDO_NAME . 'agentsetting', $record); |
|||
} |
|||
Cache::deleteCache('setting', 'allagentset' . $_W['aid']); |
|||
return $return; |
|||
} |
|||
|
|||
/* |
|||
* 读取单条设置 |
|||
*/ |
|||
static function agentsetting_read($key,$aid = '') { |
|||
global $_W; |
|||
if(empty($aid)){ |
|||
$aid = $_W['aid']; |
|||
} |
|||
$settings = pdo_get(PDO_NAME . 'agentsetting', array('key' => $key, 'uniacid' => $_W['uniacid'], 'aid' => $aid), array('value')); |
|||
if (is_array($settings)) { |
|||
$settings = iunserializer($settings['value']); |
|||
} else { |
|||
$settings = array(); |
|||
} |
|||
return $settings; |
|||
} |
|||
|
|||
/* |
|||
* 存储入口配置信息 |
|||
*/ |
|||
static function saveRule($name, $url, $arr = array()) { |
|||
global $_W; |
|||
$rule = pdo_get('rule', array('uniacid' => $_W['uniacid'], 'module' => 'cover', 'name' => MODULE_NAME . $name . '入口设置')); |
|||
if (!empty($rule)) { |
|||
$keyword = pdo_get('rule_keyword', array('uniacid' => $_W['uniacid'], 'rid' => $rule['id'])); |
|||
$cover = pdo_get('cover_reply', array('uniacid' => $_W['uniacid'], 'rid' => $rule['id'])); |
|||
} |
|||
|
|||
$data = $arr; |
|||
if (empty($data['keyword'])) return '请输入关键词!'; |
|||
$keyword1 = self::keyExist($data['keyword']); |
|||
if (!empty($keyword1)) { |
|||
if ($keyword1['name'] != (MODULE_NAME . $name . '入口设置')) return '关键字已存在!'; |
|||
} |
|||
|
|||
if (!empty($rule)) { |
|||
pdo_delete('rule', array('id' => $rule['id'], 'uniacid' => $_W['uniacid'])); |
|||
pdo_delete('rule_keyword', array('rid' => $rule['id'], 'uniacid' => $_W['uniacid'])); |
|||
pdo_delete('cover_reply', array('rid' => $rule['id'], 'uniacid' => $_W['uniacid'])); |
|||
} |
|||
|
|||
$rule_data = array('uniacid' => $_W['uniacid'], 'name' => MODULE_NAME . $name . '入口设置', 'module' => 'cover', 'displayorder' => 0, 'status' => intval($data['status'])); |
|||
pdo_insert('rule', $rule_data); |
|||
$rid = pdo_insertid(); |
|||
|
|||
$keyword_data = array('uniacid' => $_W['uniacid'], 'rid' => $rid, 'module' => 'cover', 'content' => trim($data['keyword']), 'type' => 1, 'displayorder' => 0, 'status' => intval($data['status'])); |
|||
pdo_insert('rule_keyword', $keyword_data); |
|||
|
|||
$cover_data = array('uniacid' => $_W['uniacid'], 'rid' => $rid, 'module' => MODULE_NAME, 'title' => trim($data['title']), 'description' => trim($data['desc']), 'thumb' => $data['thumb'], 'url' => $url); |
|||
pdo_insert('cover_reply', $cover_data); |
|||
return '保存成功!'; |
|||
} |
|||
|
|||
/* |
|||
* 检测关键字是否存在 |
|||
*/ |
|||
static function keyExist($key = '') { |
|||
global $_W; |
|||
if (empty($key)) return NULL; |
|||
|
|||
$keyword = pdo_get('rule_keyword', array('content' => trim($key), 'uniacid' => $_W['uniacid']), array('rid')); |
|||
|
|||
if (!empty($keyword)) { |
|||
$rule = pdo_get('rule', array('id' => $keyword['rid'], 'uniacid' => $_W['uniacid'])); |
|||
if (!empty($rule)) return $rule; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Comment: 获取当前平台拥有的模块信息 |
|||
* Author: zzw |
|||
* Date: 2019/7/9 14:35 |
|||
*/ |
|||
public static function getModularInfo(){ |
|||
#1、建立默认信息 1=拥有 0=未拥有 |
|||
$default = [ |
|||
'rush' => 0 ,//抢购商品 |
|||
'groupon' => 0 ,//团购商品 |
|||
'wlfightgroup' => 0 ,//拼团商品 |
|||
'bargain' => 0 ,//砍价商品 |
|||
'wxapp' => 0 ,//小程序 |
|||
]; |
|||
#2、进行判断是否存在该模块 存在修改对应值为1 |
|||
if (p('rush')) $default['rush'] = 1;//抢购商品模块 |
|||
if (p('groupon')) $default['groupon'] = 1;//团购商品模块 |
|||
if (p('wlfightgroup')) $default['wlfightgroup'] = 1;//拼团商品模块 |
|||
if (p('bargain')) $default['bargain'] = 1;//砍价商品模块 |
|||
if (p('wxapp')) $default['wxapp'] = 1;//小程序 |
|||
|
|||
|
|||
|
|||
return $default; |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
<?php |
|||
/** |
|||
* Created by PhpStorm. |
|||
* User: jiehua |
|||
* Date: 15/5/2 |
|||
* Time: 下午6:21 |
|||
*/ |
|||
|
|||
class SignData |
|||
{ |
|||
public $signSourceData = null; |
|||
|
|||
public $sign = null; |
|||
|
|||
} |
|||
@ -0,0 +1,211 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class SingleMerchant { |
|||
|
|||
/** |
|||
* 获取指定商家信息 |
|||
* |
|||
* @access public |
|||
* @name getSingleMerchant |
|||
* @param $id 缓存标志 |
|||
* @param $select 查询参数 |
|||
* @param $where 查询条件 |
|||
* @return array |
|||
*/ |
|||
static function getSingleMerchant($id, $select, $where = array()) { |
|||
$id = intval($id); |
|||
$where['id'] = $id; |
|||
return Util::getSingelData($select, PDO_NAME . 'merchantdata', $where); |
|||
} |
|||
|
|||
/** |
|||
* 获取指定商家金额变动记录 |
|||
* |
|||
* @access public |
|||
* @name 方法名称 |
|||
* @param mixed 参数一的说明 |
|||
* @return array |
|||
*/ |
|||
static function getMoneyRecord($sid, $pindex, $psize, $ifpage) { |
|||
return Util::getNumData('*', PDO_NAME . 'merchant_money_record', array('sid' => $sid), 'createtime desc', $pindex, $psize, $ifpage); |
|||
} |
|||
|
|||
/** |
|||
* 更新商家可结算金额 |
|||
* |
|||
* @access static |
|||
* @name updateAmount |
|||
* @param $money 更新金额(元) |
|||
* @param $sid 商家ID |
|||
* @return array |
|||
*/ |
|||
static function updateAmount($money, $sid, $orderid, $type = 1, $detail = '',$plugin = 'rush') { |
|||
global $_W; |
|||
if (empty($sid)) |
|||
return FALSE; |
|||
$merchant = pdo_fetch("select amount from" . tablename(PDO_NAME . 'merchant_account') . "where uniacid={$_W['uniacid']} and sid={$sid} "); |
|||
pdo_insert(PDO_NAME . 'merchant_money_record', array('sid' => $sid, 'uniacid' => $_W['uniacid'], 'money' => $money, 'orderid' => $orderid, 'createtime' => TIMESTAMP, 'type' => $type, 'detail' => $detail)); |
|||
if($plugin == 'rush'){ |
|||
$order = pdo_get(PDO_NAME . 'rush_order', array('id' => $orderid), 'mid'); |
|||
}elseif ($plugin == 'wlfightgroup') { |
|||
$order = pdo_get(PDO_NAME . 'order', array('id' => $orderid), 'mid'); |
|||
} |
|||
if (empty($merchant)) { |
|||
return pdo_insert(PDO_NAME . 'merchant_account', array('no_money' => 0, 'sid' => $sid, 'uniacid' => $_W['uniacid'], 'uid' => $_W['uid'], 'amount' => $money, 'updatetime' => TIMESTAMP)); |
|||
} else { |
|||
return pdo_update(PDO_NAME . 'merchant_account', array('amount' => $merchant['amount'] + $money), array('sid' => $sid)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 更新指定商家的未结束金额 |
|||
* |
|||
* @access static |
|||
* @name 方法名称 |
|||
* @param $money 更新金额(元) |
|||
* @param $sid 商家ID |
|||
* @return array |
|||
*/ |
|||
static function updateNoSettlementMoney($money, $sid) { |
|||
global $_W; |
|||
if (empty($sid)) |
|||
return FALSE; |
|||
$merchant = pdo_fetch("select no_money from" . tablename(PDO_NAME . 'merchant_account') . "where uniacid={$_W['uniacid']} and sid={$sid} "); |
|||
if (empty($merchant)) { |
|||
return pdo_insert(PDO_NAME . 'merchant_account', array('no_money' => 0, 'sid' => $sid, 'uniacid' => $_W['uniacid'], 'uid' => $_W['uid'], 'amount' => 0, 'updatetime' => TIMESTAMP)); |
|||
} else { |
|||
$m = $merchant['no_money'] + $money; |
|||
if ($m < 0) |
|||
return FALSE; |
|||
else |
|||
return pdo_update(PDO_NAME . 'merchant_account', array('no_money' => $merchant['no_money'] + $money, 'updatetime' => TIMESTAMP), array('sid' => $sid)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 得到指定商家的未结算金额 |
|||
* |
|||
* @access static |
|||
* @name getNoSettlementMoney |
|||
* @param $sid 商家ID |
|||
* @return array |
|||
*/ |
|||
static function getNoSettlementMoney($sid) { |
|||
global $_W; |
|||
$merchant = pdo_fetch("select no_money from" . tablename(PDO_NAME . 'merchant_account') . "where uniacid={$_W['uniacid']} and sid={$sid} "); |
|||
return $merchant['no_money']; |
|||
} |
|||
|
|||
static function finance($openid = '', $money = 0, $desc = '') { |
|||
global $_W; |
|||
load() -> func('communication'); |
|||
$setting = uni_setting($_W['uniacid'], array('payment')); |
|||
if (empty($openid)) |
|||
return error(-1, 'openid不能为空'); |
|||
if (!is_array($setting['payment'])) |
|||
return error(1, '没有设定支付参数'); |
|||
$wechat = $setting['payment']['wechat']; |
|||
$sql = 'SELECT `key`,`secret` FROM ' . tablename('account_wechats') . ' WHERE `uniacid`=:uniacid limit 1'; |
|||
$row = pdo_fetch($sql, array(':uniacid' => $_W['uniacid'])); |
|||
$url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers'; |
|||
$pars = array(); |
|||
$pars['mch_appid'] = $row['key']; |
|||
$pars['mchid'] = $wechat['mchid']; |
|||
$pars['nonce_str'] = random(32); |
|||
$pars['partner_trade_no'] = time() . random(4, true); |
|||
$pars['openid'] = $openid; |
|||
$pars['check_name'] = 'NO_CHECK'; |
|||
$pars['amount'] = $money; |
|||
$pars['desc'] = empty($desc) ? '商家佣金提现' : $desc; |
|||
$pars['spbill_create_ip'] = gethostbyname($_SERVER["HTTP_HOST"]); |
|||
ksort($pars, SORT_STRING); |
|||
$string1 = ''; |
|||
foreach ($pars as $k => $v) { |
|||
$string1 .= "{$k}={$v}&"; |
|||
} |
|||
$string1 .= "key=" . $wechat['apikey']; |
|||
$pars['sign'] = strtoupper(md5($string1)); |
|||
$xml = array2xml($pars); |
|||
$path_cert = IA_ROOT . '/attachment/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; |
|||
//证书路径 |
|||
$path_key = IA_ROOT . '/attachment/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; |
|||
//证书路径 |
|||
if (!file_exists($path_cert) || !file_exists($path_key)) { |
|||
$path_cert = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_cert.pem'; |
|||
$path_key = IA_ROOT . '/addons/feng_fightgroups/cert/' . $_W['uniacid'] . '/apiclient_key.pem'; |
|||
} |
|||
$extras = array(); |
|||
$extras['CURLOPT_SSLCERT'] = $path_cert; |
|||
$extras['CURLOPT_SSLKEY'] = $path_key; |
|||
$resp = ihttp_request($url, $xml, $extras); |
|||
if (empty($resp['content'])) { |
|||
return error(-2, '网络错误'); |
|||
} else { |
|||
$arr = json_decode(json_encode((array) simplexml_load_string($resp['content'])), true); |
|||
$xml = '<?xml version="1.0" encoding="utf-8"?>' . $resp['content']; |
|||
$dom = new \DOMDocument(); |
|||
if ($dom -> loadXML($xml)) { |
|||
$xpath = new \DOMXPath($dom); |
|||
$code = $xpath -> evaluate('string(//xml/return_code)'); |
|||
$ret = $xpath -> evaluate('string(//xml/result_code)'); |
|||
if (strtolower($code) == 'success' && strtolower($ret) == 'success') { |
|||
return true; |
|||
} else { |
|||
$error = $xpath -> evaluate('string(//xml/err_code_des)'); |
|||
return error(-2, $error); |
|||
} |
|||
} else { |
|||
return error(-1, '未知错误'); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static function verifier($sid, $mid) { |
|||
global $_W; |
|||
if (empty($sid) || empty($mid)) return FALSE; |
|||
$merchantuser = pdo_fetch("SELECT * FROM ".tablename(PDO_NAME."merchantuser") |
|||
." WHERE storeid = {$sid} AND mid = {$mid} AND uniacid = {$_W['uniacid']} AND enabled = 1 AND ismain IN (1,2,3) "); |
|||
/* $merchantuser = Util::getSingelData("*" , PDO_NAME . 'merchantuser' |
|||
, ['storeid' => $sid , 'mid' => $mid,'uniacid'=>$_W['uniacid'],'enabled'=>1]);*/ |
|||
if ($merchantuser) return TRUE; |
|||
else return FALSE; |
|||
} |
|||
|
|||
static function verifRecordAdd($aid, $sid, $mid, $plugin, $orderid, $verifcode, $remark,$type,$num = 1,$verifmid = '',$time = '') { |
|||
global $_W; |
|||
if (empty($sid) || empty($mid) || empty($plugin) || empty($verifcode) || empty($remark)) { |
|||
return FALSE; |
|||
} |
|||
if(empty($verifmid)){ |
|||
$verifmid = $_W['mid']; |
|||
} |
|||
if(empty($time)){ |
|||
$time = time(); |
|||
} |
|||
$flagtime = time() - 5; |
|||
$flag = pdo_fetch("SELECT id FROM ".tablename('wlmerchant_verifrecord')."WHERE plugin = '{$plugin}' AND verifrcode = {$verifcode} AND createtime > {$flagtime} "); |
|||
if(empty($flag)){ |
|||
$merchantuser = Util::getSingelData("name,mobile", PDO_NAME . 'merchantuser', array('storeid' => $sid, 'mid' => $verifmid)); |
|||
if (empty($merchantuser['name']) || empty($merchantuser['mobile'])) { |
|||
$member = pdo_get(PDO_NAME . "member", array('id' => $verifmid), array('nickname', 'mobile')); |
|||
$merchantuser['name'] = empty($merchantuser['name']) ? $member['nickname'] : $merchantuser['name']; |
|||
$merchantuser['mobile'] = empty($merchantuser['mobile']) ? $member['mobile'] : $merchantuser['mobile']; |
|||
} |
|||
$rush_activity = array(); |
|||
if($orderid>0){ |
|||
if($plugin == 'rush'){ |
|||
$rush_order = pdo_get(PDO_NAME.'rush_order',array('id'=>$orderid),['orderno','activityid']); |
|||
$orderno = $rush_order['orderno']; |
|||
$rush_activity = pdo_getcolumn(PDO_NAME.'rush_activity',['id' => $rush_order['activityid']],'cc_id'); |
|||
}else{ |
|||
$orderno = pdo_getcolumn(PDO_NAME.'order',array('id'=>$orderid),'orderno'); |
|||
} |
|||
} |
|||
$record = array('uniacid' => $_W['uniacid'],'num' => $num,'aid' => $aid, 'storeid' => $sid, 'mid' => $mid, 'plugin' => $plugin, 'orderid' => $orderid,'orderno'=>$orderno,'verifrcode' => $verifcode, 'verifmid' => $verifmid, 'verifnickname' => $merchantuser['name'], 'verifmobile' => $merchantuser['mobile'], 'remark' => $remark, 'createtime' => $time,'type' => $type); |
|||
if ($rush_activity) $record['cc_id'] = $rush_activity['cc_id']; |
|||
pdo_insert(PDO_NAME . 'verifrecord', $record); |
|||
return TRUE; |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,328 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Tools { |
|||
|
|||
static function getPosterTemp() { |
|||
$templist = array(); |
|||
for ($i = 1; $i < 12; $i++) { |
|||
$templist[$i] = array('bg' => URL_APP_RESOURCE . '/image/poster/' . 'bg' . $i . '.jpg', 'nail' => URL_APP_RESOURCE . '/image/poster/' . 's_bg' . $i . '.jpg'); |
|||
} |
|||
return $templist; |
|||
} |
|||
|
|||
static function getRealData($data) { |
|||
$data['left'] = intval(str_replace('px', '', $data['left'])) * 2; |
|||
$data['top'] = intval(str_replace('px', '', $data['top'])) * 2; |
|||
$data['width'] = intval(str_replace('px', '', $data['width'])) * 2; |
|||
$data['height'] = intval(str_replace('px', '', $data['height'])) * 2; |
|||
$data['size'] = intval(str_replace('px', '', $data['size'])) * 2; |
|||
$data['src'] = tomedia($data['src']); |
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* 图片圆角 |
|||
* @param bool $target |
|||
* @param bool $circle |
|||
* @return resource |
|||
*/ |
|||
static function imageRadius($target = false, $circle = false) { |
|||
/* //1、创建画布 |
|||
$im = imagecreatetruecolor(300,200);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。 |
|||
//2、绘制所需要的图像 |
|||
$red = imagecolorallocate($im,255,0,0);//创建一个颜色,以供使用 |
|||
imageellipse($im,30,30,40,40,$red);//画一个圆。参数说明:30,30为圆形的中心坐标;40,40为宽和高,不一样时为椭圆;$red为圆形的颜色(框颜色) |
|||
//3、输出图像 |
|||
header("content-type: image/png"); |
|||
imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 |
|||
//4、销毁图像,释放内存 |
|||
imagedestroy($im);die;*/ |
|||
$w = imagesx($target); |
|||
$h = imagesy($target); |
|||
$w = min($w, $h); |
|||
$h = $w; |
|||
$img = imagecreatetruecolor($w, $h); |
|||
imagesavealpha($img, true); |
|||
$bg = imagecolorallocatealpha($img, 255, 255, 255, 127); |
|||
imagefill($img, 0, 0, $bg); |
|||
$radius = $circle ? $w / 2 : 20; |
|||
$r = $radius; |
|||
$x = 0; |
|||
|
|||
while ($x < $w) { |
|||
$y = 0; |
|||
while ($y < $h) { |
|||
$rgbColor = imagecolorat($target, $x, $y); |
|||
if ($radius <= $x && $x <= $w - $radius || $radius <= $y && $y <= $h - $radius) { |
|||
imagesetpixel($img, $x, $y, $rgbColor); |
|||
} else { |
|||
$y_x = $r; |
|||
$y_y = $r; |
|||
if (($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r) { |
|||
imagesetpixel($img, $x, $y, $rgbColor); |
|||
} |
|||
|
|||
$y_x = $w - $r; |
|||
$y_y = $r; |
|||
if (($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r) { |
|||
imagesetpixel($img, $x, $y, $rgbColor); |
|||
} |
|||
|
|||
$y_x = $r; |
|||
$y_y = $h - $r; |
|||
if (($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r) { |
|||
imagesetpixel($img, $x, $y, $rgbColor); |
|||
} |
|||
|
|||
$y_x = $w - $r; |
|||
$y_y = $h - $r; |
|||
if (($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r) { |
|||
imagesetpixel($img, $x, $y, $rgbColor); |
|||
} |
|||
} |
|||
++$y; |
|||
} |
|||
++$x; |
|||
} |
|||
return $img; |
|||
} |
|||
|
|||
static function createImage($imgurl) { |
|||
@ini_set('memory_limit', '512M'); |
|||
load()->func('communication'); |
|||
$resp = ihttp_request($imgurl); |
|||
|
|||
if ($resp['code'] == 200 && !empty($resp['content'])) { |
|||
return imagecreatefromstring($resp['content']); |
|||
} |
|||
if ($resp['errno'] == 35) { |
|||
$imgurl = str_replace(array('https://'), 'http://', $imgurl); |
|||
} |
|||
|
|||
$i = 0; |
|||
while ($i < 3) { |
|||
$resp = ihttp_request($imgurl); |
|||
if ($resp['code'] == 200 && !empty($resp['content'])) { |
|||
return imagecreatefromstring($resp['content']); |
|||
} |
|||
|
|||
++$i; |
|||
} |
|||
|
|||
|
|||
//以上方法都未获取图片资源 |
|||
$resp = file_get_contents($imgurl); |
|||
return imagecreatefromstring($resp); |
|||
} |
|||
|
|||
static function mergeImage($target, $data, $imgurl) { |
|||
$img = self::createImage($imgurl); |
|||
$w = imagesx($img); |
|||
$h = imagesy($img); |
|||
if ($data['appoint']) { |
|||
$w = $data['width']; |
|||
$h = $data['height']; |
|||
} |
|||
if ($data['border'] == 'radius' || $data['border'] == 'circle') { |
|||
$img = self::imageRadius($img, $data['border'] == 'circle'); |
|||
$number = $data['width']; |
|||
if ($w > $h) { |
|||
$width = $number; |
|||
$height = $width / $w * $h; |
|||
} else if ($w < $h) { |
|||
$height = $number; |
|||
$width = $height / $h * $w; |
|||
} else { |
|||
$width = $number; |
|||
$height = $number; |
|||
} |
|||
$wh = min([$w, $h]); |
|||
$minWh = min([$width, $height]); |
|||
imagecopyresized($target, $img, $data['left'], $data['top'], 0, 0, $minWh, $minWh, $wh, $wh); |
|||
imagedestroy($img); |
|||
return $target; |
|||
} |
|||
if ($data['position'] == 'cover') { |
|||
$oldheight = $data['height']; |
|||
$data['height'] = $data['width'] * $h / $w; |
|||
if ($data['height'] > $oldheight) { |
|||
$data['top'] = $data['top'] - ($data['height'] - $oldheight) / 2; |
|||
} |
|||
} |
|||
|
|||
imagecopyresized($target, $img, $data['left'], $data['top'], 0, 0, $data['width'], $data['height'], $w, $h); |
|||
imagedestroy($img); |
|||
|
|||
return $target; |
|||
} |
|||
|
|||
static function mergeText($target, $data, $text) { |
|||
$font = IA_ROOT . '/addons/' . MODULE_NAME . '/web/resource/fonts/pingfang.ttf'; |
|||
if (!is_file($font)) { |
|||
$font = IA_ROOT . '/addons/' . MODULE_NAME . '/web/resource/fonts/msyh.ttf'; |
|||
} |
|||
$colors = self::hex2rgb($data['color']); |
|||
// 自动换行处理 |
|||
$text = self::autowrap($data['size'], 0, $font, $text, $data['width'], $data['line']); |
|||
//文字居中 |
|||
if ($data['align'] == 'center') { |
|||
$textbox = imagettfbbox($data['size'], 0, $font, $text); |
|||
$textwidth = $textbox[4] - $textbox[6]; |
|||
$data['left'] = $data['left'] + ($data['width'] / 2 - $textwidth / 2); |
|||
} |
|||
$text = mb_convert_encoding($text, "html-entities", "utf-8"); |
|||
$color = imagecolorallocate($target, $colors['red'], $colors['green'], $colors['blue']); |
|||
imagettftext($target, $data['size'], 0, $data['left'], $data['top'] + $data['size'], $color, $font, $text); |
|||
|
|||
return $target; |
|||
} |
|||
|
|||
//画线 |
|||
protected static function mergeLine($target, $data) { |
|||
$colors = self::hex2rgb($data['color']); |
|||
$color = imagecolorallocate($target, $colors['red'], $colors['green'], $colors['blue']); |
|||
imageline($target, $data['left'], $data['top'], $data['left'] + $data['width'], $data['top'] + $data['height'], $color); |
|||
return $target; |
|||
} |
|||
|
|||
// 这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度 |
|||
static function autowrap($fontsize, $angle, $fontface, $string, $width, $needhang = 1) { |
|||
$content = ""; |
|||
$hang = 1; |
|||
// 将字符串拆分成一个个单字 保存到数组 letter 中 |
|||
for ($i = 0; $i < mb_strlen($string, 'UTF8'); $i++) { |
|||
$letter[] = mb_substr($string, $i, 1, 'UTF8'); |
|||
} |
|||
foreach ($letter as $l) { |
|||
$teststr = $content . " " . $l; |
|||
$testbox = imagettfbbox($fontsize, $angle, $fontface, $teststr); |
|||
// 判断拼接后的字符串是否超过预设的宽度 |
|||
if (($testbox[2] > $width) && ($content !== "")) { |
|||
if ($hang < $needhang) { |
|||
$content .= "\n"; |
|||
$hang++; |
|||
} else { |
|||
break; |
|||
} |
|||
} |
|||
$content .= $l; |
|||
} |
|||
return $content; |
|||
} |
|||
|
|||
static function hex2rgb($colour) { |
|||
if ($colour[0] == '#') { |
|||
$colour = substr($colour, 1); |
|||
} |
|||
|
|||
if (strlen($colour) == 6) { |
|||
list($r, $g, $b) = array($colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5]); |
|||
} else if (strlen($colour) == 3) { |
|||
list($r, $g, $b) = array($colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2]); |
|||
} else { |
|||
return false; |
|||
} |
|||
|
|||
$r = hexdec($r); |
|||
$g = hexdec($g); |
|||
$b = hexdec($b); |
|||
return array('red' => $r, 'green' => $g, 'blue' => $b); |
|||
} |
|||
|
|||
static function createPoster($poster, $filename = '', $member, $width = 640) { |
|||
global $_W; |
|||
$path = IA_ROOT . '/addons/' . MODULE_NAME . '/data/poster/' . $_W['uniacid'] . '/'; |
|||
if (!is_dir($path)) { |
|||
load()->func('file'); |
|||
mkdirs($path); |
|||
} |
|||
$md5 = $filename ? $filename : md5(json_encode(array('openid' => $member['openid'], 'time' => time()))); |
|||
$file = $md5 . '.png'; |
|||
//if (!is_file($path . $file)) { |
|||
if(1==1){ |
|||
set_time_limit(0); |
|||
@ini_set('memory_limit', '512M'); |
|||
$bg = self::createImage(tomedia($poster['bg'])); |
|||
$target = imagecreatetruecolor($width, imagesy($bg)); |
|||
imagecopy($target, $bg, 0, 0, 0, 0, $width, imagesy($bg)); |
|||
imagedestroy($bg); |
|||
$data = json_decode(str_replace('"', '\'', $poster['data']), true); |
|||
$textArr = ['vip_price', 'nickname', 'title', 'sub_title', 'text', 'shopTitle', 'shopAddress', 'shopPhone', |
|||
'position', 'company_branch', 'address', 'mobile', 'desc', 'wechat', 'name', 'numbers']; |
|||
foreach ($data as $d) { |
|||
$d = self::getRealData($d); |
|||
if ($d['type'] == 'head') { |
|||
$avatar = preg_replace('/\\/0$/i', '/96', $poster['avatar']); |
|||
$target = self::mergeImage($target, $d, $avatar); |
|||
} else if ($d['type'] == 'img') { |
|||
$target = self::mergeImage($target, $d, $d['src']); |
|||
} else if ($d['type'] == 'qr') { |
|||
$target = self::mergeImage($target, $d, $poster['qrimg']); |
|||
} else if (in_array($d['type'], $textArr)) { |
|||
$textContent = ($d['type'] == 'text') ? $d['words'] : $poster[$d['type']]; |
|||
$textContent = str_replace(['“','”'],['"','"'],$textContent); |
|||
$textContent = htmlspecialchars_decode($textContent); |
|||
|
|||
$target = self::mergeText($target, $d, $textContent); |
|||
} else if ($d['type'] == 'line') { |
|||
$target = self::mergeLine($target, $d); |
|||
} else { |
|||
if ($d['type'] == 'thumb' || $d['type'] == 'shopThumb' || $d['type'] == 'logo') { |
|||
$thumb = tomedia($poster[$d['type']]); |
|||
$target = self::mergeImage($target, $d, $thumb); |
|||
} else if ($d['type'] == 'marketprice' || $d['type'] == 'productprice') { |
|||
$target = self::mergeText($target, $d, is_numeric($poster[$d['type']]) ? '¥' . $poster[$d['type']] : $poster[$d['type']]); |
|||
} |
|||
} |
|||
} |
|||
imagepng($target, $path . $file); |
|||
// header("content-type: image/png"); |
|||
// imagepng($target);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 |
|||
// imagedestroy($target);die; |
|||
imagedestroy($target); |
|||
} |
|||
$img = $_W['siteroot'] . 'addons/' . MODULE_NAME . '/data/poster/' . $_W['uniacid'] . '/' . $file; |
|||
return $img; |
|||
} |
|||
|
|||
static function clearposter() { |
|||
global $_W; |
|||
load()->func('file'); |
|||
@rmdirs(IA_ROOT . '/addons/' . MODULE_NAME . '/data/poster/' . $_W['uniacid']); |
|||
@rmdirs(ATTACHMENT_ROOT . 'images/' . $_W['uniacid'] . '/media.upload/'); |
|||
} |
|||
|
|||
static function clearwxapp() { |
|||
global $_W; |
|||
load()->func('file'); |
|||
@rmdirs(IA_ROOT . '/addons/' . MODULE_NAME . '/data/wxapp/' . $_W['uniacid']); |
|||
} |
|||
|
|||
static function get_head_img($url, $num) { |
|||
$imgs_array = array(); |
|||
$random_array = array(); |
|||
$files = array(); |
|||
if ($handle = opendir($url)) { |
|||
while (false !== ($file = readdir($handle))) { |
|||
if ($file != "." && $file != "..") { |
|||
if (substr($file, -3) == 'gif' || substr($file, -3) == 'jpg') { |
|||
$files[count($files)] = $file; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
closedir($handle); |
|||
for ($i = 0; $i < $num; $i++) { |
|||
$random = rand(0, count($files) - 1); |
|||
while (in_array($random, $random_array)) { |
|||
$random = rand(0, count($files) - 1); |
|||
} |
|||
$random_array[$i] = $random; |
|||
$imgs_url = $url . "/" . $files[$random]; |
|||
$imgs_array[$i] = $imgs_url; |
|||
|
|||
} |
|||
return $imgs_array; |
|||
} |
|||
} |
|||
@ -0,0 +1,589 @@ |
|||
<?php |
|||
/** |
|||
* Comment: 上传文件(图片/视频/音频)的处理 |
|||
* Author: zzw |
|||
* Class UploadFile |
|||
*/ |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
use Qiniu\Auth; |
|||
use Qiniu\Storage\UploadManager; |
|||
use Qiniu\Processing\PersistentFop; |
|||
class UploadFile extends Commons { |
|||
/** |
|||
* Comment: 开始进行文件上传操作 |
|||
* Author: zzw |
|||
* Date: 2019/7/22 17:52 |
|||
* @param array 文件信息 |
|||
* @param $type 1=普通上传;2=微信端上传 |
|||
* @param int $id |
|||
* @param $module_name // 自定义存储目录名 |
|||
* @throws Exception |
|||
*/ |
|||
public static function uploadIndex($file = [],$type = 1,$id = 0,$params = [],$module_name = ''){ |
|||
global $_W,$_GPC; |
|||
try { |
|||
#1、根据内容进行操作 $type:1=普通上传;2=微信上传 |
|||
if($type == 1){ |
|||
//普通的上传操作 |
|||
if (count($file) > 0) { |
|||
//循环进行文件的处理 |
|||
$path = self::uploadHandle($file,$module_name); |
|||
//附件信息储存 只有存在params信息时才进行储存存在 目前仅后台存在 |
|||
if($params) self::saveAttachmentInfo($params,$path); |
|||
//$videoInfo = UploadFile::videoInfoHandle($path['image']); |
|||
//$path['img'] = $videoInfo['link']; |
|||
//返回结果信息,返回图片链接信息 |
|||
if($_GPC['is_base'] == 1){ |
|||
self::sRenderSuccess('文件上传成功' , [ |
|||
'image' => base64_encode($path['image']) , |
|||
//'img' => base64_encode($videoInfo['link']) , |
|||
'img' => base64_encode($path['img']) , |
|||
'info' => base64_encode($path) , |
|||
]); |
|||
}else { |
|||
self::sRenderSuccess('文件上传成功',$path); |
|||
} |
|||
}else{ |
|||
self::sRenderError('请上传文件'); |
|||
} |
|||
}else{ |
|||
//文件上传在微信端口,需要进行下载操作。然后在上传 |
|||
$path = self::getWeChatImg($id); |
|||
//$videoInfo = UploadFile::videoInfoHandle($path); |
|||
//$imgPath['img'] = $videoInfo['link']; |
|||
$imgPath['image'] = $path; |
|||
$imgPath['img'] = tomedia($path); |
|||
|
|||
$imgPath['time'] = date('H:i:s',time()); |
|||
file_put_contents(PATH_DATA . "img_up.log", var_export($imgPath, true) . PHP_EOL, FILE_APPEND); |
|||
self::sRenderSuccess('文件上传成功',$imgPath); |
|||
} |
|||
} catch (Exception $e) { |
|||
self::sRenderError($e->getMessage()); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 普通上传文件的信息处理 |
|||
* Author: zzw |
|||
* Date: 2019/7/22 18:46 |
|||
* @param $file |
|||
* @param $module_name // 自定义存储目录名 |
|||
* @return array |
|||
* @throws Exception |
|||
*/ |
|||
protected static function uploadHandle($file,$module_name){ |
|||
#1、判断上传内容是否合格 |
|||
foreach($file as $key => $value){ |
|||
#1-1、获取文件类型 |
|||
$type = explode('/', ($value['type']))[0];//图片格式 |
|||
#1-2、根据类型调用判断方法 |
|||
switch ($type) { |
|||
case 'image': |
|||
self::imageJudge($value); |
|||
break;//判断图片是否合格 |
|||
case 'text' : |
|||
$filetype = explode('.', ($value['name']))[1]; |
|||
if($filetype != 'text' && $filetype != 'txt'){ |
|||
self::sRenderError("类型错误,不支持的文件!"); |
|||
} |
|||
break;//判断文件是否合格(暂无判断条件) |
|||
case 'application' : |
|||
$filetype = explode('.', ($value['name']))[1]; |
|||
if(!in_array($filetype,['crt','pem'])){ |
|||
self::sRenderError("类型错误,不支持的文件!"); |
|||
} |
|||
break;//判断文件是否合格(暂无判断条件) |
|||
case 'video' : |
|||
case 'audio' : |
|||
self::videoJudge($value); |
|||
break;//判断视频是否合格(暂无判断条件) |
|||
default: |
|||
self::sRenderError("类型错误,不支持的文件!"); |
|||
break; |
|||
} |
|||
} |
|||
#2、上传图片合格,开始进行图片的上传 |
|||
$data = []; |
|||
foreach($file as $index => $item){ |
|||
#2-1、获取文件类型 |
|||
$type = explode('/', ($value['type']))[0];//图片格式 |
|||
#2-2、根据类型调用判断方法 |
|||
switch ($type) { |
|||
case 'image': |
|||
//$data[$index]['image'] = self::imageUpload($value); |
|||
//$data[$index]['img'] = tomedia($data[$index]['image']); |
|||
$data['image'] = self::imageUpload($value,$module_name); |
|||
$data['img'] = tomedia($data['image']); |
|||
break;//图片上传 |
|||
case 'text': |
|||
case 'application': |
|||
$data['image'] = self::fileUpload($value); |
|||
$data['img'] = tomedia($data['image']); |
|||
break;//文件上传 |
|||
case 'video': |
|||
case 'audio' : |
|||
$data['image'] = self::videoUpload($value); |
|||
$data['img'] = tomedia($data['image']); |
|||
break;//文件上传 |
|||
} |
|||
} |
|||
|
|||
return $data; |
|||
} |
|||
/** |
|||
* Comment: 保存附件基本信息 |
|||
* Author: zzw |
|||
* Date: 2020/9/1 16:55 |
|||
* @param $params |
|||
* @param $path |
|||
*/ |
|||
protected static function saveAttachmentInfo($params,$path){ |
|||
global $_W; |
|||
//基本信息获取 |
|||
list($width , $height , $type) = getimagesize($path['img']);//基本参数获取 |
|||
$nameArr = explode('.' , $path['img']); |
|||
$suffix = $nameArr[count($nameArr) - 1]; |
|||
//生成储存信息 |
|||
$data = [ |
|||
'uniacid' => $params['uniacid'] , |
|||
'aid' => $params['aid'] , |
|||
'shop_id' => $params['shop_id'] , |
|||
'group_id' => $params['group_id'] , |
|||
'url' => $path['image'] , |
|||
'name' => $params['name'] , |
|||
'imagewidth' => $width ? : 0 , |
|||
'imageheight' => $height ? : 0 , |
|||
'suffix' => $suffix , |
|||
'filesize' => $params['filesize'] , |
|||
'mimetype' => $params['mimetype'] , |
|||
'uploadtime' => time() , |
|||
'storage' => $_W['setting']['remote']['type'] ? : 0 , |
|||
]; |
|||
|
|||
pdo_insert(PDO_NAME."attachment",$data); |
|||
} |
|||
|
|||
|
|||
/************** 图片上传的操作 ****************************************************************************************/ |
|||
/** |
|||
* Comment: 判断图片信息是否合格 |
|||
* Author: zzw |
|||
* Date: 2019/7/22 18:29 |
|||
* @param $info |
|||
*/ |
|||
protected static function imageJudge($info){ |
|||
global $_W; |
|||
#1、获取基本设置信息 |
|||
$setting = $_W['setting']['upload']['image']; |
|||
$imageType = $setting['extentions'];//允许上传的图片格式 |
|||
if(IMS_FAMILY != 'wl'){ |
|||
$imageSize = $setting['limit'] * 1024; |
|||
}else{ |
|||
if(Customized::init('upfile1512') > 0){ |
|||
$imageSize = 51200 * 1024; |
|||
}else{ |
|||
$imageSize = 5120 * 1024; |
|||
} |
|||
} |
|||
#2、图片格式生成 |
|||
$type = explode('/', ($info['type']))[1];//图片格式 |
|||
//判断图片格式是否允许上传 |
|||
if (!in_array(strtolower($type), $imageType) && IMS_FAMILY != 'wl' ) { |
|||
$typeStr = implode(',', $imageType); |
|||
self::sRenderError("格式错误,只能上传{$typeStr}格式的图片,当前格式:{$type}"); |
|||
} |
|||
//判断图片的大小是否合格 |
|||
if ($imageSize < $info['size']) { |
|||
$size = $imageSize / (1024 * 1024); |
|||
self::sRenderError("图片不能超过{$size}M"); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 图片上传 |
|||
* Author: zzw |
|||
* Date: 2019/7/22 18:44 |
|||
* @param $info |
|||
* @param $module_name // 自定义存储目录名 |
|||
* @return string |
|||
* @throws Exception |
|||
*/ |
|||
protected static function imageUpload($info,$module_name = ''){ |
|||
global $_W; |
|||
#1、获取基本设置信息 |
|||
$setting = $_W['setting']['upload']['image']; |
|||
$setting['folder'] = "images/". MODULE_NAME."/".$_W['uniacid']; |
|||
if (!empty($module_name)) { |
|||
$setting['folder'] = "images/". $module_name ."/".$_W['uniacid'] . "/" . date("Y/m/d") ; |
|||
} |
|||
$storageSet = $_W['wlsetting']['enclosure']['service'] ? : $_W['setting']['remote']['type'];//0=关闭;1=FTP服务器;2=阿里云;3=七牛云存储;4=腾讯云存储 |
|||
#2、图片格式后缀获取 |
|||
$type = explode('/', ($info['type']))[1];//图片格式 |
|||
$imgSuffix = '.' . strtolower($type); |
|||
#3、配置图片储存路径 |
|||
$fileName = time() . rand(10000, 99999) . $imgSuffix;//时间戳+随机数生成不重复文件名称 |
|||
$pathName = $setting['folder'] . "/" . $fileName;//文件储存路径 |
|||
$fullName = PATH_ATTACHMENT . $pathName;//文件在本地服务器暂存地址 |
|||
#4、将图片上传至本地服务器 |
|||
$imgSaveFile = PATH_ATTACHMENT.$setting['folder']; |
|||
if(!is_readable($imgSaveFile)) (is_file($imgSaveFile) || is_dir($imgSaveFile)) or mkdir($imgSaveFile,0700,true); |
|||
$res = move_uploaded_file($info['tmp_name'], $fullName); |
|||
if($res){ |
|||
//判断图片是否合格$_W['source'] |
|||
if(!array_key_exists('group_id',$_REQUEST)) { |
|||
$isQualified = Filter::init($fullName,$_W['source'],2); |
|||
}else{ |
|||
$isQualified['errno'] = 1; |
|||
} |
|||
if($isQualified['errno'] == 1){ |
|||
if($storageSet > 0){ |
|||
//将储存在本地的图片上传到远程服务器 |
|||
$remotestatus = WeliamWeChat::file_remote_upload($pathName); |
|||
if ($remotestatus) { |
|||
//WeliamWeChat::file_delete($pathName); |
|||
$tips = $remotestatus ? : '远程附件上传失败,请检查配置并重新上传'; |
|||
self::sRenderError($tips, $remotestatus); |
|||
} |
|||
} |
|||
return $pathName; |
|||
}else{ |
|||
self::sRenderError($isQualified['message']); |
|||
} |
|||
}else{ |
|||
self::sRenderError('图片上传失败,请重新上传'); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 获取微信上传的图片,储存在并且/上传到图片服务器 |
|||
* Author: zzw |
|||
* Date: 2019/7/23 16:46 |
|||
* @param $id |
|||
* @return string |
|||
* @throws Exception |
|||
*/ |
|||
protected static function getWeChatImg($id){ |
|||
global $_W; |
|||
#1、获取token信息 |
|||
//$uniacccount = WeAccount::create($_W['acid']); |
|||
//$access_token = $uniacccount->fetch_available_token(); |
|||
$access_token = WeliamWeChat::getAccessToken(true); |
|||
#2、生成请求地址 |
|||
//$url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . trim($access_token) . '&media_id=' . trim($id); |
|||
$url = "https://file.api.weixin.qq.com/cgi-bin/media/get?access_token={$access_token}&media_id=" . trim($id); |
|||
#3、请求获取内容 |
|||
$res = ihttp_get($url); |
|||
#4、判断内容是否符合条件 |
|||
$setting = $_W['setting']['upload']['image']; |
|||
if(IMS_FAMILY == 'wl'){ |
|||
if(Customized::init('upfile1512') > 0){ |
|||
$setting['limit'] = 51200; |
|||
}else{ |
|||
$setting['limit'] = 5120; |
|||
} |
|||
} |
|||
$setting['folder'] = "images/".MODULE_NAME."/" .$_W['uniacid']. '/' . date('Y/m/d', time()); |
|||
//判断提取是否成功 |
|||
if (is_error($res)) self::sRenderError('提取文件失败, 错误信息: ' . $res['message']); |
|||
if (intval($res['code']) != 200) self::sRenderError('提取文件失败: 未找到该资源文件'); |
|||
//判断储存目录是否存在 |
|||
$path = PATH_ATTACHMENT . $setting['folder']; |
|||
if (!is_dir($path)) mkdir($path, 0777, true); |
|||
//判断文件是否过大 |
|||
if (intval($res['headers']['Content-Length']) > $setting['limit'] * 1024) self::sRenderError('上传的媒体文件过大,不能大于'. $setting['limit'] .'KB'); |
|||
if($res['content']){ |
|||
//文件内容处理 |
|||
$content = $res['content'];//条件内容 |
|||
//判断是否成功获取文件 |
|||
if(is_array(json_decode($content,true)) && json_decode($content,true)['errcode']){ |
|||
self::sRenderError(json_decode($content,true)['errmsg']); |
|||
} |
|||
#4、将图片上传至本地服务器 |
|||
$fileName = time() . rand(10000, 99999).'.png';//时间戳+随机数生成不重复文件名称 |
|||
$pathName = $setting['folder'] . "/" . $fileName; |
|||
$fullName = PATH_ATTACHMENT . $pathName; |
|||
$result = file_put_contents($fullName, $content); |
|||
if($result){ |
|||
//判断图片是否合格$_W['source'] |
|||
$isQualified = Filter::init($fullName,$_W['source'],2); |
|||
if($isQualified['errno'] == 1){ |
|||
$storageSet = $_W['wlsetting']['enclosure']['service'] ? : $_W['setting']['remote']['type'];//0=关闭;1=FTP服务器;2=阿里云;3=七牛云存储;4=腾讯云存储 |
|||
if($storageSet > 0){ |
|||
//将储存在本地的图片上传到远程服务器 |
|||
$remotestatus = WeliamWeChat::file_remote_upload($pathName); |
|||
if ($remotestatus) { |
|||
$tips = $remotestatus ? : '远程附件上传失败,请检查配置并重新上传'; |
|||
self::sRenderError($tips, $remotestatus); |
|||
} |
|||
} |
|||
return $pathName; |
|||
}else{ |
|||
self::sRenderError($isQualified['message']); |
|||
} |
|||
}else{ |
|||
self::sRenderError("提取失败,请稍后重试"); |
|||
} |
|||
}else{ |
|||
self::sRenderError("获取失败,请稍后重试"); |
|||
} |
|||
} |
|||
/************** 文件上传的操作 ****************************************************************************************/ |
|||
/** |
|||
* Comment: 储存文件(本地储存、密钥文件) |
|||
* Author: zzw |
|||
* Date: 2019/8/28 11:10 |
|||
* @param $info |
|||
* @return string |
|||
* @throws Exception |
|||
*/ |
|||
protected static function fileUpload($info){ |
|||
global $_W; |
|||
#1、公共文件储存路径 |
|||
$type = explode('.', ($info['name']));//图片格式 |
|||
$suffix = $type[count($type) - 1]; |
|||
$name = rand(1000,9999).time().".".$suffix; |
|||
$path = PATH_ATTACHMENT."public_file/".MODULE_NAME."/". $_W['uniacid']."/".date("Y-m-d",time())."/";//路径 |
|||
$link = $path.$name;//储存文件目录路径 |
|||
#2、判断路径目录是否存在 不存在建立 |
|||
if(!file_exists($path)) mkdir(iconv("UTF-8", "GBK", $path),0777,true); |
|||
#3、储存文件到本地 |
|||
$res = move_uploaded_file($info['tmp_name'], $link); |
|||
if($suffix == 'pem'){ |
|||
//密钥文件,只储存在本地 |
|||
if($res) return $_W['uniacid'].'/'.date("Y-m-d",time()).'/'.$name; |
|||
else self::sRenderError('文件上传失败,请重新上传'); |
|||
}else{ |
|||
//其他文件,传递到远程 |
|||
$fileName = "public_file/".MODULE_NAME."/" . $_W['uniacid']."/".date("Y-m-d",time())."/".$name; |
|||
if($res){ |
|||
$storageSet = $_W['wlsetting']['enclosure']['service'] ? : $_W['setting']['remote']['type'];//0=关闭;1=FTP服务器;2=阿里云;3=七牛云存储;4=腾讯云存储 |
|||
if($storageSet > 0){ |
|||
//将储存在本地的图片上传到远程服务器 |
|||
$remotestatus = WeliamWeChat::file_remote_upload($fileName); |
|||
if ($remotestatus) { |
|||
self::sRenderError('远程附件上传失败,请检查配置并重新上传', $remotestatus); |
|||
} |
|||
} |
|||
return $fileName; |
|||
}else{ |
|||
self::sRenderError("提取失败,请稍后重试"); |
|||
} |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 判断视频音频是否合格 |
|||
* Author: zzw |
|||
* Date: 2020/1/8 16:02 |
|||
* @param $info |
|||
*/ |
|||
protected static function videoJudge($info){ |
|||
global $_W; |
|||
#1、获取基本设置信息 |
|||
$setting = $_W['setting']['upload']['audio']; |
|||
$imageType = $setting['extentions'];//允许上传的格式 |
|||
if(IMS_FAMILY != 'wl'){ |
|||
$imageSize = $setting['limit'] * 1024; |
|||
}else{ |
|||
if(Customized::init('upfile1512') > 0){ |
|||
$imageSize = 51200 * 10240; |
|||
}else{ |
|||
$imageSize = 51200 * 1024; |
|||
} |
|||
} |
|||
#2、格式生成 |
|||
$type = explode('/', ($info['type']))[1];//格式 |
|||
if($type == 'quicktime') $type = 'mp4';//苹果兼容 |
|||
if($type == 'mpeg') $type = 'mp3';//苹果兼容 |
|||
//判断格式是否允许上传 独立版,不判断上传类型 |
|||
if (!in_array(strtolower($type), $imageType) && IMS_FAMILY != 'wl') { |
|||
$typeStr = implode(',', $imageType); |
|||
self::sRenderError("格式错误,只能上传{$typeStr}格式的视频音频,当前格式:{$type}"); |
|||
} |
|||
//判断大小是否合格 |
|||
if ($imageSize < $info['size']) { |
|||
$size = $imageSize / (1024 * 1024); |
|||
self::sRenderError("视频不能超过{$size}M"); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 视频文件上传 |
|||
* Author: zzw |
|||
* Date: 2020/1/8 9:32 |
|||
* @param $info |
|||
* @return string |
|||
* @throws Exception |
|||
*/ |
|||
protected static function videoUpload($info){ |
|||
global $_W; |
|||
#1、公共文件储存路径 |
|||
Util::wl_log('videoErrorInfo' , PATH_MODULE."log/" , $info , '视频远程储存日志',false); //写入日志记录 |
|||
|
|||
|
|||
$suffix = explode('/', ($info['type']))[1];//格式 |
|||
if($suffix == 'quicktime') $suffix = 'mp4';//苹果兼容 |
|||
if($suffix == 'mpeg') $suffix = 'mp3';//苹果兼容 |
|||
$name = rand(1000,9999).time().".".$suffix; |
|||
$path = PATH_ATTACHMENT . "public_file/".MODULE_NAME."/" . $_W['uniacid'] . "/" . date("Y-m-d" , time()) . "/";//路径 |
|||
$link = $path.$name;//储存文件目录路径 |
|||
#2、判断路径目录是否存在 不存在建立 |
|||
if(!file_exists($path)) mkdir(iconv("UTF-8", "GBK", $path),0777,true); |
|||
#3、储存文件到本地 |
|||
$res = move_uploaded_file($info['tmp_name'], $link); |
|||
#4、传递到远程 |
|||
$fileName = "public_file/" .MODULE_NAME."/" . $_W['uniacid'] . "/" . date("Y-m-d" , time()) . "/" . $name; |
|||
if($res){ |
|||
//判断是否开启内部远程储存 |
|||
$uploadSet = Setting::wlsetting_read("api")['upload']; |
|||
$uploadSet['type'] = 0;//强制关闭七牛云远程配置 |
|||
if($uploadSet['type'] == 1){ |
|||
//开启远程储存 使用内部远程储存 |
|||
$res = self::remoteStorage($uploadSet,$fileName); |
|||
if($res['errno'] == 0){ |
|||
//视频上传远程服务器并且截取第一帧操作失败 记录日志信息 |
|||
Util::wl_log('videoImagePath' , PATH_MODULE."log/" , $res , '视频远程储存并且截图失败日志',false); //写入日志记录 |
|||
} |
|||
}else{ |
|||
//未开启内部远程 使用微擎远程储存 |
|||
$storageSet = $_W['wlsetting']['enclosure']['service'] ? : $_W['setting']['remote']['type'];//0=关闭;1=FTP服务器;2=阿里云;3=七牛云存储;4=腾讯云存储 |
|||
if($storageSet > 0){ |
|||
//将储存在本地的图片上传到远程服务器 |
|||
$remotestatus = WeliamWeChat::file_remote_upload($fileName); |
|||
if ($remotestatus) { |
|||
self::sRenderError('远程附件上传失败,请检查配置并重新上传', $remotestatus); |
|||
} |
|||
} |
|||
} |
|||
return $fileName; |
|||
}else{ |
|||
self::sRenderError("提取失败,请稍后重试"); |
|||
} |
|||
} |
|||
|
|||
/************** 内部远程附件管理(七牛云) **************************************************************************/ |
|||
protected static $auth ;//初始化签权对象 |
|||
/** |
|||
* Comment: 视频储存到远程服务器并且获取第一帧图片作为封面图 |
|||
* Author: zzw |
|||
* Date: 2020/1/17 14:46 |
|||
* @param array $uploadSet api设置信息 |
|||
* @param string $fileName 视频文件名称(在本地的储存路径) |
|||
* @return array |
|||
* @throws Exception |
|||
*/ |
|||
public static function remoteStorage($uploadSet,$fileName){ |
|||
$accessKey = trim($uploadSet['access_key']); |
|||
$secretKey = trim($uploadSet['secret_key']); |
|||
$buckey = trim($uploadSet['bucket']);//储存空间 |
|||
$domainName = trim($uploadSet['domain_name']);//服务器域名 |
|||
$queueName = trim($uploadSet['queue_name']);//队列名称 |
|||
#1、图片名称生成 |
|||
$nameArr = explode(MODULE_NAME,$fileName); |
|||
$pathValue = explode('.',$nameArr[1]); |
|||
$imagePath = $pathValue[0].".jpg"; |
|||
/* if($pathValue[1] != 'mp4'){ |
|||
$imagePath = $pathValue[0].".jpg"; |
|||
}else{ |
|||
$imagePath = $pathValue[0]; |
|||
}*/ |
|||
$videoImagePath = 'videoImagePath'.$imagePath;//图片在远程服务器上的储存位置 |
|||
$videoImgLink = $domainName.$videoImagePath;//视频图片的链接 |
|||
$videoLink = $domainName . $fileName;//视频在服务器上面的位置 |
|||
|
|||
#2、判断视频图片是否已经存在 |
|||
if(!remoteFileExists($videoImgLink)) { |
|||
self::$auth = new Auth($accessKey , $secretKey);// 初始化签权对象 |
|||
$token = self::getRemoteStorageToken($buckey);//生成上传Token |
|||
#3、视频图片不存在 判断视频文件是否存在服务器 |
|||
if (!remoteFileExists($videoLink)) { |
|||
#1、不存在 判断视频文件是否存在本地 |
|||
$link = PATH_ATTACHMENT . $fileName; |
|||
if (!file_exists($link)) { |
|||
//文件不存在当前服务器 |
|||
return error(0 , '文件不存在当前服务器'); |
|||
} |
|||
#1、文件上传远程服务器 |
|||
$uploadMgr = new UploadManager();//构建 UploadManager 对象 |
|||
list($ret , $err) = $uploadMgr->putFile($token , $fileName , $link);//调用 UploadManager 的 putFile 方法进行文件的上传。 |
|||
unlink($link); |
|||
if ($err !== null) return error(0 , $err); |
|||
} |
|||
#4、通过远程服务器的视频 生成视频第一帧图片信息 |
|||
$notifyUrl = '';//转码完成后通知到你的业务服务器。 |
|||
$config = new \Qiniu\Config(); |
|||
//$config->useHTTPS=true; |
|||
$pfop = new PersistentFop(self::$auth , $config); |
|||
//要进行转码的转码操作。 http://developer.qiniu.com/docs/v6/api/reference/fop/av/avthumb.html |
|||
$fops = "vframe/jpg/offset/1/w/480/h/360|saveas/" . \Qiniu\base64_urlSafeEncode($buckey . ":" . $videoImagePath); //取视频第1秒的截图,图片格式为jpg,宽度为480px,高度为360px: |
|||
list($id , $err) = $pfop->execute($buckey , $fileName , $fops , $queueName , $notifyUrl , false); |
|||
if ($err != null) return error(0 , $err); |
|||
list($ret, $err) = $pfop->status($id); |
|||
//查询转码的进度和状态 http://smartcity.weliam.cn/videoImagePath/2020-03-31/60411585633284.jpg |
|||
/*echo $id,'<br />'; |
|||
list($ret, $err) = $pfop->status($id); |
|||
echo "\n====> pfop avthumb status: \n"; |
|||
if ($err != null) { |
|||
wl_debug($err); |
|||
} else { |
|||
wl_debug([$videoImgLink,$ret]); |
|||
}*/ |
|||
} |
|||
#5、输出视频上传结果 |
|||
/*$imgPath['video_img'] = $videoImgLink; |
|||
$imgPath['image'] = $videoLink; |
|||
$imgPath['img'] = $videoLink; |
|||
self::sRenderSuccess('文件上传成功',$imgPath);*/ |
|||
return error(1,$videoImgLink); |
|||
} |
|||
/** |
|||
* Comment: 获取视频上传token |
|||
* Author: zzw |
|||
* Date: 2020/1/16 18:00 |
|||
* @param $bucket |
|||
* @return mixed |
|||
*/ |
|||
protected static function getRemoteStorageToken($bucket){ |
|||
global $_W; |
|||
$name = md5('remoteStorageToken'.$bucket); |
|||
$caCheInfo = json_decode(Cache::getCache('remoteStorageToken',$name),true); |
|||
if($caCheInfo && time() < $caCheInfo['end_time']){ |
|||
$token = $caCheInfo['token'];//生成上传Token |
|||
}else{ |
|||
//获取token |
|||
$expires = 7200;//有效时间 |
|||
$token = self::$auth->uploadToken($bucket, null, $expires, null, true);//生成上传Token |
|||
//记录进入session中 |
|||
$endTime = time() + ($expires - 200); |
|||
Cache::setCache('remoteStorageToken',$name,json_encode(['token'=>$token,'end_time'=>$endTime])); |
|||
} |
|||
#2、返回token |
|||
return $token; |
|||
} |
|||
/** |
|||
* Comment: 根据视频路径 获取该视频的远程连接及第一帧图片 |
|||
* Author: zzw |
|||
* Date: 2020/1/17 17:22 |
|||
* @param $fileName |
|||
* @return mixed |
|||
*/ |
|||
public static function videoInfoHandle($fileName){ |
|||
if($fileName) { |
|||
#1、判断默认路径是否存在视频文件 不存在获取远程服务器路径 并且判断是否存在第一帧图片信息 |
|||
$newLink = tomedia($fileName); |
|||
// if (!remoteFileExists($newLink)) { |
|||
// $uploadSet = Setting::wlsetting_read("api")['upload']; |
|||
// $domainName = trim($uploadSet['domain_name']);//服务器域名 |
|||
// $nameArr = explode(MODULE_NAME , $fileName); |
|||
// $imagePath = explode('.' , $nameArr[1])[0] . ".jpg"; |
|||
// $videoImagePath = 'videoImagePath' . $imagePath;//图片在远程服务器上的储存位置 |
|||
// $videoImgLink = $domainName . $videoImagePath;//视频图片的链接 |
|||
// $newLink = $domainName . $fileName;//视频在服务器上面的位置 |
|||
// } |
|||
} |
|||
#2、信息拼装 |
|||
$data['link'] = $newLink ? $newLink : ''; |
|||
$data['img_link'] = ''; |
|||
//$data['img_link'] = $videoImgLink ? $videoImgLink : ''; |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,566 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class User { |
|||
|
|||
static function agentuser_single($user_or_uid) { |
|||
$user = $user_or_uid; |
|||
if (empty($user)) { |
|||
return false; |
|||
} |
|||
if (is_numeric($user)) { |
|||
$user = array('id' => $user); |
|||
} |
|||
if (!is_array($user)) { |
|||
return false; |
|||
} |
|||
$where = ' WHERE 1 '; |
|||
$params = array(); |
|||
if (!empty($user['id'])) { |
|||
$where .= ' AND `id`=:id'; |
|||
$params[':id'] = intval($user['id']); |
|||
} |
|||
if (!empty($user['uniacid'])) { |
|||
$where .= ' AND `uniacid`=:uniacid'; |
|||
$params[':uniacid'] = $user['uniacid']; |
|||
} |
|||
if (!empty($user['username'])) { |
|||
$where .= ' AND `username`=:username'; |
|||
$params[':username'] = $user['username']; |
|||
} |
|||
if (!empty($user['status'])) { |
|||
$where .= " AND `status`=:status"; |
|||
$params[':status'] = intval($user['status']); |
|||
} |
|||
if (empty($params)) { |
|||
return false; |
|||
} |
|||
$sql = 'SELECT * FROM ' . tablename(PDO_NAME.'agentusers') . " $where LIMIT 1"; |
|||
$record = pdo_fetch($sql, $params); |
|||
if (empty($record)) { |
|||
return false; |
|||
} |
|||
if (!empty($user['password'])) { |
|||
$password = Util::encryptedPassword($user['password'], $record['salt']); |
|||
if ($password != $record['password']) { |
|||
return false; |
|||
} |
|||
} |
|||
return $record; |
|||
} |
|||
|
|||
static function agentuser_update($user) { |
|||
if (empty($user['id']) || !is_array($user)) { |
|||
return false; |
|||
} |
|||
$record = array(); |
|||
if (!empty($user['username'])) { |
|||
$record['username'] = $user['username']; |
|||
} |
|||
if (!empty($user['password'])) { |
|||
$record['password'] = user_hash($user['password'], $user['salt']); |
|||
} |
|||
if (!empty($user['lastvisit'])) { |
|||
$record['lastvisit'] = (strlen($user['lastvisit']) == 10) ? $user['lastvisit'] : strtotime($user['lastvisit']); |
|||
} |
|||
if (!empty($user['lastip'])) { |
|||
$record['lastip'] = $user['lastip']; |
|||
} |
|||
if (isset($user['joinip'])) { |
|||
$record['joinip'] = $user['joinip']; |
|||
} |
|||
if (isset($user['remark'])) { |
|||
$record['remark'] = $user['remark']; |
|||
} |
|||
if (isset($user['status'])) { |
|||
$status = intval($user['status']); |
|||
if (!in_array($status, array(0, 1))) { |
|||
$status = 1; |
|||
} |
|||
$record['status'] = $status; |
|||
} |
|||
if (isset($user['groupid'])) { |
|||
$record['groupid'] = $user['groupid']; |
|||
} |
|||
if (isset($user['starttime'])) { |
|||
$record['starttime'] = $user['starttime']; |
|||
} |
|||
if (isset($user['endtime'])) { |
|||
$record['endtime'] = $user['endtime']; |
|||
} |
|||
if (empty($record)) { |
|||
return false; |
|||
} |
|||
return pdo_update(PDO_NAME.'agentusers', $record, array('id' => intval($user['id']))); |
|||
} |
|||
/** |
|||
* Comment: 获取个人中心菜单设置信息 |
|||
* Author: zzw |
|||
* Date: 2020/3/27 14:01 |
|||
* @return array|bool|mixed |
|||
*/ |
|||
public static function userSet(){ |
|||
global $_W; |
|||
#1、信息获取 |
|||
$set = Setting::wlsetting_read('userindex');//旧版本设置信息 |
|||
$default = static::getDefaultUserMenuList();//默认菜单信息 |
|||
//循环处理信息 |
|||
foreach($default as $key => $val){ |
|||
if(is_array($set[$key])){ |
|||
$set[$key] = array_merge($val,$set[$key]); |
|||
foreach($set[$key] as $kk => $vv){ |
|||
if($kk != 'diy_title' && !$vv){ |
|||
$set[$key][$kk] = $default[$key][$kk]; |
|||
} |
|||
} |
|||
}else{ |
|||
$set[$key] = $val; |
|||
} |
|||
} |
|||
|
|||
|
|||
// #1、信息设置 通过判断是否为一维数组 确定是否为新的设置信息 |
|||
// if (count($set , 1) == count($set)) { |
|||
// //信息错误 生成正确的信息 |
|||
// $newSet = [ |
|||
// 'kefu' => [ |
|||
// 'title' => '客服按钮' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/kf.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/kf.png' , |
|||
// 'link' => 'pages/subPages/customer/customer' , |
|||
// 'default' => 'pages/subPages/customer/customer' , |
|||
// 'switch' => $set['kefu'] ? : 1 |
|||
// ] ,//客服按钮 |
|||
// 'grzy' => [ |
|||
// 'title' => '个人主页' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzy.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzy.png' , |
|||
// 'link' => "pages/subPages/homepage/homepage/homepage?mid=&checkType=1" , |
|||
// 'default' => 'pages/subPages/homepage/homepage/homepage?mid=&checkType=1' , |
|||
// 'switch' => $set['grzy'] ? : 1 |
|||
// ] ,//个人主页 |
|||
// 'shzx' => [ |
|||
// 'title' => '商户中心' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/pos.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/pos.png' , |
|||
// 'link' => 'pages/subPages/merchant/merchantChangeShop/merchantChangeShop' , |
|||
// 'default' => 'pages/subPages/merchant/merchantChangeShop/merchantChangeShop' , |
|||
// 'switch' => $set['shzx'] ? : 1 |
|||
// ] ,//商户中心 |
|||
// 'hxjl' => [ |
|||
// 'title' => '核销记录' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/hxjl.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/hxjl.png' , |
|||
// 'link' => 'pages/subPages/writeRecord/index' , |
|||
// 'default' => 'pages/subPages/writeRecord/index' , |
|||
// 'switch' => $set['hxjl'] ? : 1 |
|||
// ] ,//核销记录 |
|||
// 'wddz' => [ |
|||
// 'title' => '我的地址' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
// 'link' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
// 'default' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
// 'switch' => $set['wddz'] ? : 1 |
|||
// ] ,//我的地址 |
|||
// ]; |
|||
// if (p('halfcard')) { |
|||
// $newSet['ykthy'] = [ |
|||
// 'title' => '一卡通会员' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/card.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/card.png' , |
|||
// 'link' => 'pages/mainPages/memberCard/memberCard' , |
|||
// 'default' => 'pages/mainPages/memberCard/memberCard' , |
|||
// 'switch' => $set['ykthy'] ? : 1 |
|||
// ];//一卡通会员 |
|||
// $newSet['xfjl'] = [ |
|||
// 'title' => '消费记录' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/consume.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/consume.png' , |
|||
// 'link' => 'pages/subPages/consumptionRecords/consumptionRecords' , |
|||
// 'default' => 'pages/subPages/consumptionRecords/consumptionRecords' , |
|||
// 'switch' => $set['xfjl'] ? : 1 |
|||
// ];//消费记录 |
|||
// } |
|||
// if (p('wlcoupon')) { |
|||
// $newSet['wdkq'] = [ |
|||
// 'title' => '我的卡券' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/coupon.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/coupon.png' , |
|||
// 'link' => 'pages/subPages/coupon/coupon' , |
|||
// 'default' => 'pages/subPages/coupon/coupon' , |
|||
// 'switch' => $set['wdkq'] ? : 1 |
|||
// ];//我的卡券 |
|||
// } |
|||
// if (p('bargain')) { |
|||
// $newSet['wdkj'] = [ |
|||
// 'title' => '我的砍价' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mykj.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mykj.png' , |
|||
// 'link' => 'pages/subPages/bargin/barginlist/barginlist' , |
|||
// 'default' => 'pages/subPages/bargin/barginlist/barginlist' , |
|||
// 'switch' => $set['wdkj'] ? : 1 |
|||
// ];//我的砍价 |
|||
// } |
|||
// if (p('consumption')) { |
|||
// $newSet['jfsc'] = [ |
|||
// 'title' => '积分商城' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/integralMall.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/integralMall.png' , |
|||
// 'link' => 'pages/subPages/integral/integralShop/integralShop' , |
|||
// 'default' => 'pages/subPages/integral/integralShop/integralShop' , |
|||
// 'switch' => $set['jfsc'] ? : 1 |
|||
// ];//积分商城 |
|||
// } |
|||
// if (p('pocket')) { |
|||
// $newSet['wdtz'] = [ |
|||
// 'title' => '我的帖子' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/invitation.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/invitation.png' , |
|||
// 'link' => 'pages/subPages/myPost/myPost' , |
|||
// 'default' => 'pages/subPages/myPost/myPost' , |
|||
// 'switch' => $set['wdtz'] ? : 1 |
|||
// ];//我的帖子 |
|||
// } |
|||
// if (p('distribution')) { |
|||
// $newSet['fxzx'] = [ |
|||
// 'title' => '分销中心' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/distribution.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/distribution.png' , |
|||
// 'link' => 'pages/subPages/dealer/index/index' , |
|||
// 'default' => 'pages/subPages/dealer/index/index' , |
|||
// 'switch' => $set['fxzx'] ? : 1 |
|||
// ];//分销中心 |
|||
// } |
|||
// if (p('helper')) { |
|||
// $newSet['bzzx'] = [ |
|||
// 'title' => '帮助中心' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/qa.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/qa.png' , |
|||
// 'link' => 'pages/subPages/helpCenter/helpCenter' , |
|||
// 'default' => 'pages/subPages/helpCenter/helpCenter' , |
|||
// 'switch' => $set['bzzx'] ? : 1 |
|||
// ];//帮助中心 |
|||
// } |
|||
// if (p('attestation')) { |
|||
// $newSet['rzzx'] = [ |
|||
// 'title' => '认证中心' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/rzzx.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/rzzx.png' , |
|||
// 'link' => 'pages/subPages/attestationCenter/index?rzType=1' , |
|||
// 'default' => 'pages/subPages/attestationCenter/index?rzType=1' , |
|||
// 'switch' => $set['rzzx'] ? : 1 |
|||
// ];//认证中心 |
|||
// } |
|||
// if (p('redpack')) { |
|||
// $newSet['wdhb'] = [ |
|||
// 'title' => '我的红包' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png' , |
|||
// 'link' => 'pages/subPages/redpacket/myredpacket' , |
|||
// 'default' => 'pages/subPages/redpacket/myredpacket' , |
|||
// 'switch' => $set['wdhb'] ? : 1 |
|||
// ];//我的红包 |
|||
// $newSet['hbgc'] = [ |
|||
// 'title' => '红包广场' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png' , |
|||
// 'link' => 'pages/subPages/redpacket/redsquare' , |
|||
// 'default' => 'pages/subPages/redpacket/redsquare' , |
|||
// 'switch' => $set['hbgc'] ? : 1 |
|||
// ];//红包广场 |
|||
// } |
|||
// //设置默认在最后面 |
|||
// $newSet['sz'] = [ |
|||
// 'title' => '设置' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/setting.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/setting.png' , |
|||
// 'link' => 'pages/mainPages/userset/userset' , |
|||
// 'default' => 'pages/mainPages/userset/userset' , |
|||
// 'switch' => 1 |
|||
// ];//设置 |
|||
// $set = $newSet; |
|||
// } |
|||
// //补丁:判断是否存在我的地址 |
|||
// if(!in_array('wddz',array_keys($set))){ |
|||
// $set['wddz'] = [ |
|||
// 'title' => '我的地址' , |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
// 'link' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
// 'default' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
// 'switch' => $set['wddz'] ? : 1 |
|||
// ]; |
|||
// } |
|||
// if (p('redpack')) { |
|||
// if(!in_array('wdhb',array_keys($set))) { |
|||
// $set['wdhb'] = [ |
|||
// 'title' => '我的红包', |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png', |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png', |
|||
// 'link' => 'pages/subPages/redpacket/myredpacket', |
|||
// 'default' => 'pages/subPages/redpacket/myredpacket', |
|||
// 'switch' => $set['wdhb'] ?: 1 |
|||
// ];//我的红包 |
|||
// } |
|||
// if(!in_array('hbgc',array_keys($set))) { |
|||
// $set['hbgc'] = [ |
|||
// 'title' => '红包广场', |
|||
// 'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png', |
|||
// 'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png', |
|||
// 'link' => 'pages/subPages/redpacket/redsquare', |
|||
// 'default' => 'pages/subPages/redpacket/redsquare', |
|||
// 'switch' => $set['hbgc'] ?: 1 |
|||
// ];//红包广场 |
|||
// } |
|||
// } |
|||
// //补丁:修改默认图片信息 |
|||
// $set['kefu']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/kf.png'; |
|||
// $set['grzy']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzy.png'; |
|||
// $set['shzx']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/pos.png'; |
|||
// $set['hxjl']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/hxjl.png'; |
|||
// $set['wddz']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png'; |
|||
// if (p('halfcard')) { |
|||
// $set['ykthy']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/card.png'; |
|||
// $set['xfjl']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/consume.png'; |
|||
// } |
|||
// if (p('wlcoupon')) { |
|||
// $set['wdkq']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/coupon.png'; |
|||
// } |
|||
// if (p('bargain')) { |
|||
// $set['wdkj']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mykj.png'; |
|||
// } |
|||
// if (p('consumption')) { |
|||
// $set['jfsc']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/integralMall.png'; |
|||
// } |
|||
// if (p('pocket')) { |
|||
// $set['wdtz']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/invitation.png'; |
|||
// } |
|||
// if (p('distribution')) { |
|||
// $set['fxzx']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/distribution.png'; |
|||
// } |
|||
// if (p('helper')) { |
|||
// $set['bzzx']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/qa.png'; |
|||
// } |
|||
// if (p('attestation')) { |
|||
// $set['rzzx']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/rzzx.png'; |
|||
// } |
|||
// if (p('redpack')) { |
|||
// $set['wdhb']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png'; |
|||
// $set['hbgc']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png'; |
|||
// } |
|||
// $set['sz']['image'] = '/addons/weliam_smartcity/h5/resource/wxapp/merchant/setting.png'; |
|||
|
|||
return $set; |
|||
} |
|||
/** |
|||
* Comment: 获取用户中心默认菜单信息 |
|||
* Author: zzw |
|||
* Date: 2020/8/7 18:06 |
|||
* @return array |
|||
*/ |
|||
protected static function getDefaultUserMenuList(){ |
|||
//信息错误 生成正确的信息 |
|||
$set = Setting::wlsetting_read('userindex');//旧版本设置信息 |
|||
$newSet = [ |
|||
'kefu' => [ |
|||
'title' => '客服按钮' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/kf.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/kf.png' , |
|||
'link' => 'pages/subPages/customer/customer' , |
|||
'default' => 'pages/subPages/customer/customer' , |
|||
'switch' => is_array($set['kefu']) ? $set['kefu']['switch'] : 1 , |
|||
] ,//客服按钮 |
|||
'grzy' => [ |
|||
'title' => '个人主页' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzy.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzy.png' , |
|||
'link' => "pages/subPages/homepage/homepage/homepage?mid=&checkType=1" , |
|||
'default' => 'pages/subPages/homepage/homepage/homepage?mid=&checkType=1' , |
|||
'switch' => is_array($set['grzy']) ? $set['grzy']['switch'] : 1 , |
|||
] ,//个人主页 |
|||
'shzx' => [ |
|||
'title' => '商户中心' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/pos.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/pos.png' , |
|||
'link' => 'pages/subPages/merchant/merchantChangeShop/merchantChangeShop' , |
|||
'default' => 'pages/subPages/merchant/merchantChangeShop/merchantChangeShop' , |
|||
'switch' => is_array($set['shzx']) ? $set['shzx']['switch'] : 1 , |
|||
] ,//商户中心 |
|||
'hxjl' => [ |
|||
'title' => '核销记录' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/hxjl.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/hxjl.png' , |
|||
'link' => 'pages/subPages/writeRecord/index' , |
|||
'default' => 'pages/subPages/writeRecord/index' , |
|||
'switch' => is_array($set['hxjl']) ? $set['hxjl']['switch'] : 1 , |
|||
] ,//核销记录 |
|||
'wddz' => [ |
|||
'title' => '我的地址' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mineWhere.png' , |
|||
'link' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
'default' => 'pages/subPages/receivingAddress/receivingAddress' , |
|||
'switch' => is_array($set['wddz']) ? $set['wddz']['switch'] : 1 , |
|||
] ,//我的地址 |
|||
]; |
|||
if (p('halfcard')) { |
|||
$newSet['ykthy'] = [ |
|||
'title' => '一卡通会员' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/card.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/card.png' , |
|||
'link' => 'pages/mainPages/memberCard/memberCard' , |
|||
'default' => 'pages/mainPages/memberCard/memberCard' , |
|||
'switch' => is_array($set['ykthy']) ? $set['ykthy']['switch'] : 1 , |
|||
];//一卡通会员 |
|||
$newSet['xfjl'] = [ |
|||
'title' => '消费记录' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/consume.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/consume.png' , |
|||
'link' => 'pages/subPages/consumptionRecords/consumptionRecords' , |
|||
'default' => 'pages/subPages/consumptionRecords/consumptionRecords' , |
|||
'switch' => is_array($set['xfjl']) ? $set['xfjl']['switch'] : 1 , |
|||
];//消费记录 |
|||
} |
|||
if (p('wlcoupon')) { |
|||
$newSet['wdkq'] = [ |
|||
'title' => '我的卡券' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/coupon.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/coupon.png' , |
|||
'link' => 'pages/subPages/coupon/coupon' , |
|||
'default' => 'pages/subPages/coupon/coupon' , |
|||
'switch' => is_array($set['wdkq']) ? $set['wdkq']['switch'] : 1 , |
|||
];//我的卡券 |
|||
} |
|||
if (p('bargain')) { |
|||
$newSet['wdkj'] = [ |
|||
'title' => '我的砍价' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mykj.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/mykj.png' , |
|||
'link' => 'pages/subPages/bargin/barginlist/barginlist' , |
|||
'default' => 'pages/subPages/bargin/barginlist/barginlist' , |
|||
'switch' => is_array($set['wdkj']) ? $set['wdkj']['switch'] : 1 , |
|||
];//我的砍价 |
|||
} |
|||
if (p('consumption')) { |
|||
$newSet['jfsc'] = [ |
|||
'title' => '积分商城' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/integralMall.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/integralMall.png' , |
|||
'link' => 'pages/subPages/integral/integralShop/integralShop' , |
|||
'default' => 'pages/subPages/integral/integralShop/integralShop' , |
|||
'switch' => is_array($set['jfsc']) ? $set['jfsc']['switch'] : 1 , |
|||
];//积分商城 |
|||
} |
|||
if (p('pocket')) { |
|||
$newSet['wdtz'] = [ |
|||
'title' => '我的帖子' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/invitation.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/invitation.png' , |
|||
'link' => 'pages/subPages/myPost/myPost' , |
|||
'default' => 'pages/subPages/myPost/myPost' , |
|||
'switch' => is_array($set['wdtz']) ? $set['wdtz']['switch'] : 1 , |
|||
];//我的帖子 |
|||
} |
|||
if (p('distribution')) { |
|||
$newSet['fxzx'] = [ |
|||
'title' => '分销中心' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/distribution.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/distribution.png' , |
|||
'link' => 'pages/subPages/dealer/index/index' , |
|||
'default' => 'pages/subPages/dealer/index/index' , |
|||
'switch' => is_array($set['fxzx']) ? $set['fxzx']['switch'] : 1 , |
|||
];//分销中心 |
|||
|
|||
if(Customized::init('distributionText') > 0){ |
|||
$newSet['fxzx']['title'] = '共享股东中心'; |
|||
} |
|||
} |
|||
if (p('helper')) { |
|||
$newSet['bzzx'] = [ |
|||
'title' => '帮助中心' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/qa.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/qa.png' , |
|||
'link' => 'pages/subPages/helpCenter/helpCenter' , |
|||
'default' => 'pages/subPages/helpCenter/helpCenter' , |
|||
'switch' => is_array($set['bzzx']) ? $set['bzzx']['switch'] : 1 , |
|||
];//帮助中心 |
|||
} |
|||
if (p('attestation')) { |
|||
$newSet['rzzx'] = [ |
|||
'title' => '认证中心' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/rzzx.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/rzzx.png' , |
|||
'link' => 'pages/subPages/attestationCenter/index?rzType=1' , |
|||
'default' => 'pages/subPages/attestationCenter/index?rzType=1' , |
|||
'switch' => is_array($set['rzzx']) ? $set['rzzx']['switch'] : 1 , |
|||
];//认证中心 |
|||
} |
|||
if (p('redpack')) { |
|||
$newSet['wdhb'] = [ |
|||
'title' => '我的红包' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/RedPacket_sq.png' , |
|||
'link' => 'pages/subPages/redpacket/myredpacket' , |
|||
'default' => 'pages/subPages/redpacket/myredpacket' , |
|||
'switch' => is_array($set['wdhb']) ? $set['wdhb']['switch'] : 1 , |
|||
];//我的红包 |
|||
$newSet['hbgc'] = [ |
|||
'title' => '红包广场' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/myRedPacket.png' , |
|||
'link' => 'pages/subPages/redpacket/redsquare' , |
|||
'default' => 'pages/subPages/redpacket/redsquare' , |
|||
'switch' => is_array($set['hbgc']) ? $set['hbgc']['switch'] : 1 , |
|||
];//红包广场 |
|||
} |
|||
if (p('recruit')) { |
|||
$newSet['wdjl'] = [ |
|||
'title' => '我的简历' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdjl.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdjl.png' , |
|||
'link' => 'pages/subPages2/hirePlatform/addResume/addResume' , |
|||
'default' => 'pages/subPages2/hirePlatform/addResume/addResume' , |
|||
'switch' => is_array($set['wdjl']) ? $set['wdjl']['switch'] : 1 , |
|||
];//我的简历 |
|||
$newSet['wdzp'] = [ |
|||
'title' => '我的招聘' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzp.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdzp.png' , |
|||
'link' => 'pages/subPages2/hirePlatform/recruitmentEnter/recruitmentEnter' , |
|||
'default' => 'pages/subPages2/hirePlatform/recruitmentEnter/recruitmentEnter' , |
|||
'switch' => is_array($set['wdzp']) ? $set['wdzp']['switch'] : 1 , |
|||
];//我的招聘 |
|||
$newSet['wdqz'] = [ |
|||
'title' => '我的求职' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdqz.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/wdqz.png' , |
|||
'link' => 'pages/subPages2/hirePlatform/deliverList/deliverList' , |
|||
'default' => 'pages/subPages2/hirePlatform/deliverList/deliverList' , |
|||
'switch' => is_array($set['wdzp']) ? $set['wdzp']['switch'] : 1 , |
|||
];//我的招聘 |
|||
} |
|||
|
|||
//设置默认在最后面 |
|||
$newSet['sz'] = [ |
|||
'title' => '设置' , |
|||
'icon' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/setting.png' , |
|||
'image' => '/addons/weliam_smartcity/h5/resource/wxapp/merchant/setting.png' , |
|||
'link' => 'pages/mainPages/userset/userset' , |
|||
'default' => 'pages/mainPages/userset/userset' , |
|||
'switch' => is_array($set['sz']) ? $set['sz']['switch'] : 1 , |
|||
];//设置 |
|||
return $newSet; |
|||
} |
|||
|
|||
static public function getUserIdentityList() |
|||
{ |
|||
$where = ['status' => 1]; |
|||
return pdo_getall(PDO_NAME . 'member_identity',$where,['id','name']); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,40 @@ |
|||
<?php |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class Userlabel { |
|||
|
|||
static function addlabel($mid, $goodsid, $type) { |
|||
global $_W; |
|||
if ($type == 'rush') { |
|||
$labels = pdo_getcolumn(PDO_NAME . 'rush_activity', array('id' => $goodsid), 'userlabel'); |
|||
} else if ($type == 'fightgroup') { |
|||
$labels = pdo_getcolumn(PDO_NAME . 'fightgroup_goods', array('id' => $goodsid), 'userlabel'); |
|||
} else if ($type == 'coupon') { |
|||
$labels = pdo_getcolumn(PDO_NAME . 'couponlist', array('id' => $goodsid), 'userlabel'); |
|||
} |
|||
|
|||
$labels = unserialize($labels); |
|||
if ($labels) { |
|||
foreach ($labels as $key => $label) { |
|||
$record = pdo_get(PDO_NAME . 'userlabel_record', array('mid' => $mid, 'labelid' => $label), array('id', 'times')); |
|||
if ($record) { |
|||
$data['times'] = $record['times'] + 1; |
|||
$data['dotime'] = time(); |
|||
pdo_update(PDO_NAME . 'userlabel_record', $data, array('id' => $record['id'])); |
|||
} else { |
|||
$data2 = array( |
|||
'uniacid' => $_W['uniacid'], |
|||
'aid' => $_W['aid'], |
|||
'labelid' => $label, |
|||
'mid' => $mid, |
|||
'times' => 1, |
|||
'createtime' => time(), |
|||
'dotime' => time() |
|||
); |
|||
pdo_insert(PDO_NAME . 'userlabel_record', $data2); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,347 @@ |
|||
<?php |
|||
/** |
|||
* Comment: 语音播报收款内容 |
|||
* Author: ZZW |
|||
* Date: 2018/12/29 |
|||
* Time: 15:21 |
|||
*/ |
|||
defined('IN_IA') or exit('Access Denied'); |
|||
|
|||
class VoiceAnnouncements{ |
|||
static protected $hornID, //云喇叭的id |
|||
$signature,//网关验证信息 |
|||
$uid,//用户uid |
|||
$https = 'https://api.gateway.letoiot.com/',//智联博众请求的服务器地址 |
|||
$apiUrl = "https://speaker.17laimai.cn/",//零度请求的服务器地址 |
|||
$price,//播报的接收金额 |
|||
$vol,//音量设置 |
|||
$manfactorDeviceType,//硬件厂商设备类型 |
|||
$pt,//支付类型 0=通用(不播报前缀);1=支付宝;2=微信支付;3=云支付;4=余额支付;5=微信储值;6=微信买单;7=银联刷卡;25=哆啦宝 |
|||
$pwd;//用户密码 |
|||
/** |
|||
* Comment: 向云喇叭服务器推送要播报的语音信息 |
|||
* Author: zzw |
|||
* Date: 2020/6/2 9:58 |
|||
* @param int|string|float $price 支付金额 |
|||
* @param int|string $sid 商户id | 出租车id |
|||
* @param int|string $paytype 支付方式(本平台) |
|||
* @param string $plugin 支付模块 |
|||
* @return array|bool|mixed |
|||
*/ |
|||
public static function PushVoiceMessage($price,$sid,$paytype,$plugin = ''){ |
|||
#1、获取当前商户云喇叭配置配置信息 |
|||
if(strtolower($plugin) == 'taxipay'){ |
|||
//出租车语音播报 sid为出租车id |
|||
$info = unserialize(pdo_getcolumn(PDO_NAME . "taxipay_master" , ['id' => $sid] , 'cloudspeaker')); |
|||
$info['voice'] = 2;//出租车语音固定为零度 |
|||
}else{ |
|||
//其他支付语音播报 |
|||
$info = unserialize(pdo_getcolumn(PDO_NAME . "merchantdata" , ['id' => $sid] , 'cloudspeaker')); |
|||
} |
|||
#2、判断云喇叭是否开启 状态:0=关闭,1=开启 |
|||
if($info['state'] == 1){ |
|||
//开启 |
|||
self::$price = $price * 100;//支付金额处理 |
|||
//判断使用的喇叭类型 类型:1=智联博众,2=零度 |
|||
if($info['voice'] == 2){ |
|||
//使用零度 |
|||
return self::initLD($info,$paytype); |
|||
}else{ |
|||
//使用智联博众 |
|||
return self::voiceZLBZ($paytype,$info); |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
|
|||
/****** 智联博众云喇叭使用操作 ***************************************************************************************/ |
|||
/** |
|||
* Comment: 智联博众云喇叭使用 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 16:46 |
|||
* @param $paytype |
|||
* @return array|bool |
|||
*/ |
|||
protected static function voiceZLBZ($paytype,$info){ |
|||
$paymentType = self::getPayType($paytype); |
|||
if(empty($info['id']) || empty($info['account']) || empty($info['password']) || $paymentType == 0){ |
|||
return false; |
|||
} |
|||
#2、获取基本要使用的信息 |
|||
self::$hornID = $info['id'];//喇叭id |
|||
self::$uid = $info['account'];//喇叭账号id:API_CMKJ0057 |
|||
self::$pwd = $info['password'];//喇叭密码pwd:API_LTCMKJ0057 |
|||
self::$vol = $info['volume'];//音量 |
|||
self::$pt = $paymentType; |
|||
self::$manfactorDeviceType = '03ea00020030';//$info['equipment_type']; |
|||
|
|||
self::$signature = self::getSignature(); |
|||
#3、云喇叭在线 推送收款信息 |
|||
$result = self::sendOutInfo(); |
|||
return $result; |
|||
} |
|||
/** |
|||
* Comment: 获取网关签名 |
|||
* Author: zzw |
|||
*/ |
|||
protected static function getSignature(){ |
|||
//$signature = Util::getCookie("voiceSignature")[0]; |
|||
//if(empty($signature) || !$signature){ |
|||
$postData = json_encode(array('app_cust_id'=>self::$uid,'app_cust_pwd'=>self::$pwd)); |
|||
$url = self::$https."gateway/api/v2/getSignature"; |
|||
$header = array('application/json;charset=utf-8'); |
|||
$info = self::curlRequest($url,$postData,$header); |
|||
$signature = $info['data']['signature'];//获取的签名详细内容 |
|||
//$time = $info['data']['remainTime'];//剩余的时间 (分钟) |
|||
//Util::setCookie('voiceSignature',array($signature),$time*59); |
|||
//} |
|||
return $signature; |
|||
} |
|||
/** |
|||
* Comment: 发送支付推送消息 |
|||
* Author: zzw |
|||
* @return array |
|||
*/ |
|||
protected static function sendOutInfo(){ |
|||
$descs = urlencode('支付消息');//这里请求中不能带有中文 否则报错 |
|||
$codeInfo = '?id='.self::$hornID. '&uid='.self::$uid. |
|||
'&vol='.self::$vol.'&price='.self::$price.'&pt='.self::$pt.'&seq=666&descs='.$descs; |
|||
$url = self::$https."speaker/add.php".$codeInfo; |
|||
$header = array( |
|||
'Content-Type: application/x-www-form-urlencoded;charset=utf-8', |
|||
'Authorization: '.self::$signature, |
|||
); |
|||
$info = self::curlRequest($url,'',$header); |
|||
if($info['errcode'] == 0){ |
|||
return array('erron'=>1,'message'=>'收款消息推送成功'); |
|||
}else{ |
|||
return array('erron'=>0,'message'=>$info['errmsg']); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 通过本网站的付款方式获取云喇叭的付款方式的值 |
|||
* Author: zzw |
|||
* @param $paytype |
|||
* @return int |
|||
*/ |
|||
protected static function getPayType($paytype){ |
|||
//0=通用(不播报前缀);1=支付宝;2=微信支付;3=云支付;4=余额支付;5=微信储值;6=微信买单;7=银联刷卡;25=哆啦宝 |
|||
$val = 0;//默认 通用(不播报前缀) 为0暂不进行播报 |
|||
switch ($paytype){ |
|||
case 3:$val=1;break;//支付宝 |
|||
case 2:$val=2;break;//微信支付 |
|||
case 5:$val=2;break;//微信支付 |
|||
case 1:$val=4;break;//余额支付 |
|||
} |
|||
return $val; |
|||
} |
|||
/** |
|||
* Comment: 通过curl进行网络信息抓取 |
|||
* Author: zzw |
|||
* @param $url |
|||
* @param $postData |
|||
* @param $header |
|||
* @return mixed |
|||
*/ |
|||
protected static function curlRequest($url,$postData,$header){ |
|||
$curl = curl_init();//初始化 |
|||
curl_setopt($curl, CURLOPT_URL, $url);//设置抓取的url |
|||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);//设置header信息 |
|||
curl_setopt($curl, CURLOPT_HEADER, 1);//设置头文件的信息作为数据流输出 |
|||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//设置获取的信息以文件流的形式返回,而不是直接输出。 |
|||
curl_setopt($curl, CURLOPT_POST, 1);//设置post方式提交 |
|||
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); |
|||
$data = curl_exec($curl); //执行命令 |
|||
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);// 获得响应结果里的:header头大小 |
|||
$info = substr($data, $headerSize);//通过截取 获取body信息 |
|||
curl_close($curl);//关闭URL请求 |
|||
|
|||
|
|||
return json_decode($info,true);//返回获取的信息数据 |
|||
} |
|||
/****** 零度云喇叭【商户】使用操作 ***********************************************************************************/ |
|||
/** |
|||
* Comment: 零度云喇叭使用操作 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 18:26 |
|||
* @param array $info 操作时传递的参数信息 |
|||
* @param string $type 操作类型:voice=支付语音播报,bind=商户绑定/解除绑定 |
|||
* @param string|int $payType 本平台的支付方式:1=余额,2=微信,3=支付宝; |
|||
* @return bool|mixed |
|||
*/ |
|||
public static function initLD($info,$payType = ''){ |
|||
//判断是否绑定 |
|||
$bindData = [ |
|||
'id' => $info['ld_id'],//云喇叭id |
|||
'm' => 1 ,//0为解绑,1为绑定,4强制解绑(不需提供原 USERID) |
|||
'token' => '105827801114' ,//代理商token |
|||
'uid' => 'u'.$info['ld_id'] |
|||
]; |
|||
$bindInfo = self::getBindInfo($bindData);//获取喇叭绑定信息 |
|||
$records = json_decode($bindInfo['records'],true); |
|||
$tokenAgentId = substr($bindData['token'],0,4);//云喇叭代理商id 为token前四位数 |
|||
$userIdAgentId = substr($records['userid'],-4);//云喇叭代理商id 为userid后四位 |
|||
if(!$userIdAgentId || $tokenAgentId == $userIdAgentId) { |
|||
//未绑定 自动绑定 |
|||
$bindRes = self::bind($bindData); |
|||
} |
|||
//语音播报 |
|||
$info['ld_token'] = '105827801114'; |
|||
//根据设置调用语音播报 |
|||
if($info['ld_temp']){ |
|||
//使用自定义模板 |
|||
return self::sendDiyVoice($info,$payType); |
|||
}else{ |
|||
//使用默认模板 |
|||
return self::sendVoice($info,$payType); |
|||
} |
|||
} |
|||
/** |
|||
* Comment: 请求获取当前云喇叭绑定信息 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 17:15 |
|||
* @param array $info 参数配置信息 |
|||
* @return mixed |
|||
*/ |
|||
protected static function getBindInfo($info){ |
|||
//参数信息配置 |
|||
$url = self::$apiUrl . 'list_bind.php'; |
|||
$data = [ |
|||
'id' => $info['id'] ,//云喇叭id |
|||
'token' => $info['token'] ,//代理商token |
|||
]; |
|||
//返回请求结果 |
|||
return curlPostRequest($url, $data); |
|||
} |
|||
/** |
|||
* Comment: 进行绑定 | 解除绑定 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 17:25 |
|||
* @param $info |
|||
* @return mixed |
|||
*/ |
|||
protected static function bind($info){ |
|||
global $_W; |
|||
//参数信息配置 |
|||
$url = self::$apiUrl . 'bind.php'; |
|||
$data = [ |
|||
'id' => $info['id'] ,//云喇叭id |
|||
'm' => $info['m'] ,//0为解绑,1为绑定,4强制解绑(不需提供原 USERID) |
|||
'token' => $info['token'] ,//代理商token |
|||
//用户帐号ID,自定义 |
|||
//商户命名规则:uid + 公众号id + 下划线 + sid + 商户id |
|||
//出租车命名规则:uid + 公众号id + 下划线 + lid + 商户id |
|||
'uid' => $info['uid'], |
|||
]; |
|||
//返回请求结果 |
|||
return curlPostRequest($url, $data); |
|||
} |
|||
/** |
|||
* Comment: 支付方式转换 —— 代码 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 18:25 |
|||
* @param $payType |
|||
* @return int |
|||
*/ |
|||
protected static function getVoicePayType($payType){ |
|||
#本平台支付方式(payType):1=余额;2=微信;3=支付宝 |
|||
#云喇叭支付方式(返回值):1=支付宝,2=微信支付,3=云支付,4=余额支付,5=微信储值,6=微信买单,7=银联刷卡,8=会员卡消费,9=会员卡充值 |
|||
#10=翼支付,11=退款,12=支付宝退款,13=微信退款,14=银行卡退款,15=银联退款,16=工行e支付,18=QQ钱包到账,19=京东支付,20=用户取消支付,22=西银惠支付 |
|||
$val = 0;//默认不进行播报 |
|||
switch ($payType){ |
|||
case 3:$val=1;break;//支付宝 |
|||
case 2:$val=2;break;//微信支付 |
|||
case 1:$val=4;break;//余额支付 |
|||
} |
|||
return $val; |
|||
} |
|||
/** |
|||
* Comment: 支付方式转换 —— 汉字 |
|||
* Author: zzw |
|||
* Date: 2020/6/10 17:24 |
|||
* @param $payType |
|||
* @return int |
|||
*/ |
|||
protected static function getVoicePayTypeText($payType){ |
|||
#本平台支付方式(payType):1=余额;2=微信;3=支付宝 |
|||
#云喇叭支付方式(返回值):1=支付宝,2=微信支付,3=云支付,4=余额支付,5=微信储值,6=微信买单,7=银联刷卡,8=会员卡消费,9=会员卡充值 |
|||
#10=翼支付,11=退款,12=支付宝退款,13=微信退款,14=银行卡退款,15=银联退款,16=工行e支付,18=QQ钱包到账,19=京东支付,20=用户取消支付,22=西银惠支付 |
|||
$val = 0;//默认不进行播报 |
|||
switch ($payType){ |
|||
case 3:$val='支付宝';break;//支付宝 |
|||
case 2:$val='微信';break;//微信支付 |
|||
case 1:$val='余额';break;//余额支付 |
|||
} |
|||
return $val; |
|||
} |
|||
|
|||
|
|||
/** |
|||
* Comment: 推送消息进行语音播报 —— 默认方式 |
|||
* Author: zzw |
|||
* Date: 2020/6/1 18:26 |
|||
* @param $info |
|||
* @param $payType |
|||
* @return mixed |
|||
*/ |
|||
protected static function sendVoice($info,$payType){ |
|||
//参数信息配置 |
|||
$url = self::$apiUrl . 'add.php'; |
|||
$data = [ |
|||
'id' => $info['ld_id'] ,//云喇叭id |
|||
'price' => self::$price ,//支付金额 |
|||
'pt' => self::getVoicePayType($payType) ,//云喇叭平台的支付方式 |
|||
'token' => $info['ld_token'] ,//代理商token |
|||
'version' => $info['version'] ? : 1, |
|||
'speed' => $info['speed'] ? : 50 |
|||
]; |
|||
//返回请求结果 |
|||
return curlPostRequest($url, $data); |
|||
} |
|||
/** |
|||
* Comment: 自定义语音播报信息 |
|||
* Author: zzw |
|||
* Date: 2020/6/10 17:31 |
|||
* @param $info |
|||
* @param $payType |
|||
* @return mixed |
|||
*/ |
|||
protected static function sendDiyVoice($info,$payType){ |
|||
$payTypeText = self::getVoicePayTypeText($payType); |
|||
$price = sprintf("%.2f",(self::$price / 100)); |
|||
//模板变量替换 [金额] [支付方式] |
|||
$info['ld_temp'] = str_replace('[金额]' , $price , $info['ld_temp']); |
|||
$info['ld_temp'] = str_replace('[支付方式]' , $payTypeText , $info['ld_temp']); |
|||
//参数信息配置 |
|||
$url = self::$apiUrl . 'notify.php'; |
|||
$data = [ |
|||
'id' => $info['ld_id'] ,//云喇叭id |
|||
'token' => $info['ld_token'] ,//代理商token |
|||
'message' => $info['ld_temp'] ,//播报内容 |
|||
'speed' => $info['speed'] ? : 50,//播报语速 |
|||
'version' => $info['version'] ? : 1,//接口版本 |
|||
]; |
|||
//返回请求结果 |
|||
return curlPostRequest($url, $data); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Loading…
Reference in new issue