parent
95b370a8e7
commit
25ce72a985
@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DtApp\ThinkLibrary\service\taobao;
|
||||||
|
|
||||||
|
use DtApp\ThinkLibrary\Service;
|
||||||
|
use TbkScInvitecodeGetRequest;
|
||||||
|
use TopClient;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝服务
|
||||||
|
* Class TaoBaoService
|
||||||
|
* @package DtApp\ThinkLibrary\service\taobao
|
||||||
|
*/
|
||||||
|
class TaoBaoService extends Service
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* TOP分配给应用的
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $app_key, $app_secret = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要发送的的参数
|
||||||
|
* @var
|
||||||
|
*/
|
||||||
|
private $param;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应内容
|
||||||
|
* @var
|
||||||
|
*/
|
||||||
|
private $output;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置应用的AppKey
|
||||||
|
* @param string $appKey
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function appKey(string $appKey): self
|
||||||
|
{
|
||||||
|
$this->app_key = $appKey;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用AppSecret
|
||||||
|
* @param string $appSecret
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function appSecret(string $appSecret): self
|
||||||
|
{
|
||||||
|
$this->app_secret = $appSecret;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求参数
|
||||||
|
* @param array $param
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function param(array $param): self
|
||||||
|
{
|
||||||
|
$this->param = $param;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function scInvitecodeGet($sessionKey): self
|
||||||
|
{
|
||||||
|
$c = new TopClient();
|
||||||
|
$c->appkey = $this->app_key;
|
||||||
|
$c->secretKey = $this->app_secret;
|
||||||
|
$req = new TbkScInvitecodeGetRequest();
|
||||||
|
if (isset($this->param['relation_id'])) {
|
||||||
|
$req->setRelationId($this->param['relation_id']);
|
||||||
|
}
|
||||||
|
if (isset($this->param['relation_app'])) {
|
||||||
|
$req->setRelationApp($this->param['relation_app']);
|
||||||
|
}
|
||||||
|
if (isset($this->param['code_type'])) {
|
||||||
|
$req->setCodeType($this->param['code_type']);
|
||||||
|
}
|
||||||
|
$resp = $c->execute($req, $sessionKey);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回Array
|
||||||
|
* @return array|mixed
|
||||||
|
*/
|
||||||
|
public function toArray()
|
||||||
|
{
|
||||||
|
if (isset($this->output['error_response'])) {
|
||||||
|
// 错误
|
||||||
|
if (is_array($this->output)) {
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
if (is_object($this->output)) {
|
||||||
|
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
return json_decode($this->output, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 正常
|
||||||
|
if (is_array($this->output)) {
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
if (is_object($this->output)) {
|
||||||
|
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
|
||||||
|
}
|
||||||
|
$this->output = json_decode($this->output, true);
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Autoloader{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类库自动加载,写死路径,确保不加载其他文件。
|
||||||
|
* @param string $class 对象类名
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function autoload($class) {
|
||||||
|
$name = $class;
|
||||||
|
if(false !== strpos($name,'\\')){
|
||||||
|
$name = strstr($class, '\\', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/top/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/top/request/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/top/domain/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/aliyun/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/aliyun/request/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/aliyun/domain/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/dingtalk/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/dingtalk/request/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/dingtalk/domain/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = TOP_AUTOLOADER_PATH."/QimenCloud/".$name.".php";
|
||||||
|
if(is_file($filename)) {
|
||||||
|
include $filename;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spl_autoload_register('Autoloader::autoload');
|
||||||
|
?>
|
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
include "TopSdk.php";
|
||||||
|
date_default_timezone_set('Asia/Shanghai');
|
||||||
|
|
||||||
|
$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
|
||||||
|
$req = new OapiMediaUploadRequest;
|
||||||
|
$req->setType("image");
|
||||||
|
$req->setMedia(array('type'=>'application/octet-stream','filename'=>'image.png', 'content' => file_get_contents('/Users/test/image.png')));
|
||||||
|
$resp=$c->execute($req, "******","https://oapi.dingtalk.com/media/upload");
|
||||||
|
var_dump($resp)
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: zuodeng
|
||||||
|
* Date: 2018/7/18
|
||||||
|
* Time: 上午11:31
|
||||||
|
*/
|
||||||
|
class DingTalkConstant
|
||||||
|
{
|
||||||
|
static $CALL_TYPE_OAPI = "oapi";
|
||||||
|
static $CALL_TYPE_TOP = "top";
|
||||||
|
|
||||||
|
static $METHOD_POST = "POST";
|
||||||
|
static $METHOD_GET = "GET";
|
||||||
|
|
||||||
|
static $FORMAT_JSON = "json";
|
||||||
|
static $FORMAT_XML = "xml";
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class ApplicationVar
|
||||||
|
{
|
||||||
|
var $save_file;
|
||||||
|
var $application = null;
|
||||||
|
var $app_data = '';
|
||||||
|
var $__writed = false;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->save_file = __DIR__.'/httpdns.conf' ;
|
||||||
|
$this->application = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($var_name,$var_value)
|
||||||
|
{
|
||||||
|
if (!is_string($var_name) || empty($var_name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$this->application[$var_name] = $var_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function write(){
|
||||||
|
$this->app_data = @serialize($this->application);
|
||||||
|
$this->__writeToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
if (!is_file($this->save_file))
|
||||||
|
$this->__writeToFile();
|
||||||
|
return @unserialize(@file_get_contents($this->save_file));
|
||||||
|
}
|
||||||
|
|
||||||
|
function __writeToFile()
|
||||||
|
{
|
||||||
|
$fp = @fopen($this->save_file,"w");
|
||||||
|
if(flock($fp , LOCK_EX | LOCK_NB)){
|
||||||
|
@fwrite($fp,$this->app_data);
|
||||||
|
flock($fp , LOCK_UN);
|
||||||
|
}
|
||||||
|
@fclose($fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
@ -0,0 +1,199 @@
|
|||||||
|
<?php
|
||||||
|
class ClusterTopClient extends TopClient {
|
||||||
|
|
||||||
|
private static $dnsconfig;
|
||||||
|
private static $syncDate = 0;
|
||||||
|
private static $applicationVar ;
|
||||||
|
private static $cfgDuration = 10;
|
||||||
|
|
||||||
|
public function __construct($appkey = "",$secretKey = ""){
|
||||||
|
ClusterTopClient::$applicationVar = new ApplicationVar;
|
||||||
|
$this->appkey = $appkey;
|
||||||
|
$this->secretKey = $secretKey ;
|
||||||
|
$saveConfig = ClusterTopClient::$applicationVar->getValue();
|
||||||
|
|
||||||
|
if($saveConfig){
|
||||||
|
$tmpConfig = $saveConfig['dnsconfig'];
|
||||||
|
ClusterTopClient::$dnsconfig = $this->object_to_array($tmpConfig);
|
||||||
|
unset($tmpConfig);
|
||||||
|
|
||||||
|
ClusterTopClient::$syncDate = $saveConfig['syncDate'];
|
||||||
|
if(!ClusterTopClient::$syncDate)
|
||||||
|
ClusterTopClient::$syncDate = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct(){
|
||||||
|
if(ClusterTopClient::$dnsconfig && ClusterTopClient::$syncDate){
|
||||||
|
ClusterTopClient::$applicationVar->setValue("dnsconfig",ClusterTopClient::$dnsconfig);
|
||||||
|
ClusterTopClient::$applicationVar->setValue("syncDate",ClusterTopClient::$syncDate);
|
||||||
|
ClusterTopClient::$applicationVar->write();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute($request = null, $session = null,$bestUrl = null){
|
||||||
|
$currentDate = date('U');
|
||||||
|
$syncDuration = $this->getDnsConfigSyncDuration();
|
||||||
|
$bestUrl = $this->getBestVipUrl($this->gatewayUrl,$request->getApiMethodName(),$session);
|
||||||
|
if($currentDate - ClusterTopClient::$syncDate > $syncDuration * 60){
|
||||||
|
$httpdns = new HttpdnsGetRequest;
|
||||||
|
ClusterTopClient::$dnsconfig = json_decode(parent::execute($httpdns,null,$bestUrl)->result,true);
|
||||||
|
$syncDate = date('U');
|
||||||
|
ClusterTopClient::$syncDate = $syncDate ;
|
||||||
|
}
|
||||||
|
return parent::execute($request,$session,$bestUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDnsConfigSyncDuration(){
|
||||||
|
if(ClusterTopClient::$cfgDuration){
|
||||||
|
return ClusterTopClient::$cfgDuration;
|
||||||
|
}
|
||||||
|
if(!ClusterTopClient::$dnsconfig){
|
||||||
|
return ClusterTopClient::$cfgDuration;
|
||||||
|
}
|
||||||
|
$config = json_encode(ClusterTopClient::$dnsconfig);
|
||||||
|
if(!$config){
|
||||||
|
return ClusterTopClient::$cfgDuration;
|
||||||
|
}
|
||||||
|
$config = ClusterTopClient::$dnsconfig['config'];
|
||||||
|
$duration = $config['interval'];
|
||||||
|
ClusterTopClient::$cfgDuration = $duration;
|
||||||
|
|
||||||
|
return ClusterTopClient::$cfgDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getBestVipUrl($url,$apiname = null,$session = null){
|
||||||
|
$config = ClusterTopClient::$dnsconfig['config'];
|
||||||
|
$degrade = $config['degrade'];
|
||||||
|
if(strcmp($degrade,'true') == 0){
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
$currentEnv = $this->getEnvByApiName($apiname,$session);
|
||||||
|
$vip = $this->getVipByEnv($url,$currentEnv);
|
||||||
|
if($vip)
|
||||||
|
return $vip;
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getVipByEnv($comUrl,$currentEnv){
|
||||||
|
$urlSchema = parse_url($comUrl);
|
||||||
|
if(!$urlSchema)
|
||||||
|
return null;
|
||||||
|
if(!ClusterTopClient::$dnsconfig['env'])
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if(!array_key_exists($currentEnv,ClusterTopClient::$dnsconfig['env']))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
$hostList = ClusterTopClient::$dnsconfig['env'][$currentEnv];
|
||||||
|
if(!$hostList)
|
||||||
|
return null ;
|
||||||
|
|
||||||
|
$vipList = null;
|
||||||
|
foreach ($hostList as $key => $value) {
|
||||||
|
if(strcmp($key,$urlSchema['host']) == 0 && strcmp($value['proto'],$urlSchema['scheme']) == 0){
|
||||||
|
$vipList = $value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$vip = $this->getRandomWeightElement($vipList['vip']);
|
||||||
|
|
||||||
|
if($vip){
|
||||||
|
return $urlSchema['scheme']."://".$vip.$urlSchema['path'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEnvByApiName($apiName,$session=""){
|
||||||
|
$apiCfgArray = ClusterTopClient::$dnsconfig['api'];
|
||||||
|
if($apiCfgArray){
|
||||||
|
if(array_key_exists($apiName,$apiCfgArray)){
|
||||||
|
$apiCfg = $apiCfgArray[$apiName];
|
||||||
|
if(array_key_exists('user',$apiCfg)){
|
||||||
|
$userFlag = $apiCfg['user'];
|
||||||
|
$flag = $this->getUserFlag($session);
|
||||||
|
if($userFlag && $flag ){
|
||||||
|
return $this->getEnvBySessionFlag($userFlag,$flag);
|
||||||
|
}else{
|
||||||
|
return $this->getRandomWeightElement($apiCfg['rule']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->getDeafultEnv();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getUserFlag($session){
|
||||||
|
if($session && strlen($session) > 5){
|
||||||
|
if($session[0] == '6' || $session[0] == '7'){
|
||||||
|
return $session[strlen($session) -1];
|
||||||
|
}else if($session[0] == '5' || $session[0] == '8'){
|
||||||
|
return $session[5];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEnvBySessionFlag($targetConfig,$flag){
|
||||||
|
if($flag){
|
||||||
|
$userConf = ClusterTopClient::$dnsconfig['user'];
|
||||||
|
$cfgArry = $userConf[$targetConfig];
|
||||||
|
foreach ($cfgArry as $key => $value) {
|
||||||
|
if(in_array($flag,$value))
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRandomWeightElement($elements){
|
||||||
|
$totalWeight = 0;
|
||||||
|
if($elements){
|
||||||
|
foreach ($elements as $ele) {
|
||||||
|
$weight = $this->getElementWeight($ele);
|
||||||
|
$r = $this->randomFloat() * ($weight + $totalWeight);
|
||||||
|
if($r >= $totalWeight){
|
||||||
|
$selected = $ele;
|
||||||
|
}
|
||||||
|
$totalWeight += $weight;
|
||||||
|
}
|
||||||
|
if($selected){
|
||||||
|
return $this->getElementValue($selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getElementWeight($ele){
|
||||||
|
$params = explode('|', $ele);
|
||||||
|
return floatval($params[1]);
|
||||||
|
}
|
||||||
|
private function getElementValue($ele){
|
||||||
|
$params = explode('|', $ele);
|
||||||
|
return $params[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getDeafultEnv(){
|
||||||
|
return ClusterTopClient::$dnsconfig['config']['def_env'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function startsWith($haystack, $needle) {
|
||||||
|
return $needle === "" || strpos($haystack, $needle) === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function object_to_array($obj)
|
||||||
|
{
|
||||||
|
$_arr= is_object($obj) ? get_object_vars($obj) : $obj;
|
||||||
|
foreach($_arr as $key=> $val)
|
||||||
|
{
|
||||||
|
$val= (is_array($val) || is_object($val))? $this->object_to_array($val) : $val;
|
||||||
|
$arr[$key] = $val;
|
||||||
|
}
|
||||||
|
return$arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function randomFloat($min = 0, $max = 1) { return $min + mt_rand() / mt_getrandmax() * ($max - $min); }
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class HttpdnsGetRequest
|
||||||
|
{
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.httpdns.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check(){}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* API入参静态检查类
|
||||||
|
* 可以对API的参数类型、长度、最大值等进行校验
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
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(is_array($value) && count($value) == 0)
|
||||||
|
return true;
|
||||||
|
if(is_string($value) &&trim($value) === "")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 返回的默认类
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2015-01-20
|
||||||
|
*/
|
||||||
|
class ResultSet
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回的错误码
|
||||||
|
**/
|
||||||
|
public $code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回的错误信息
|
||||||
|
**/
|
||||||
|
public $msg;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Data
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 共享字段 - 渠道或会员列表
|
||||||
|
**/
|
||||||
|
public $inviter_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道专属pidList
|
||||||
|
**/
|
||||||
|
public $root_pid_channel_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 共享字段 - 总记录数
|
||||||
|
**/
|
||||||
|
public $total_count;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展属性
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Extend
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* empty
|
||||||
|
**/
|
||||||
|
public $empty;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库详细信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class FavoritesDetail
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库id
|
||||||
|
**/
|
||||||
|
public $favorites_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库标题
|
||||||
|
**/
|
||||||
|
public $favorites_title;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class FavoritesInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库详细信息
|
||||||
|
**/
|
||||||
|
public $favorites_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选品库总数量
|
||||||
|
**/
|
||||||
|
public $total_count;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品数据
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Items
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聚划算价格,单位分
|
||||||
|
**/
|
||||||
|
public $act_price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 类目名称
|
||||||
|
**/
|
||||||
|
public $category_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* itemId
|
||||||
|
**/
|
||||||
|
public $item_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品卖点
|
||||||
|
**/
|
||||||
|
public $item_usp_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 聚划算id
|
||||||
|
**/
|
||||||
|
public $ju_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开团结束时间
|
||||||
|
**/
|
||||||
|
public $online_end_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开团时间
|
||||||
|
**/
|
||||||
|
public $online_start_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原价
|
||||||
|
**/
|
||||||
|
public $orig_price;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否包邮
|
||||||
|
**/
|
||||||
|
public $pay_postage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pc链接
|
||||||
|
**/
|
||||||
|
public $pc_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pc主图
|
||||||
|
**/
|
||||||
|
public $pic_url_for_p_c;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无线主图
|
||||||
|
**/
|
||||||
|
public $pic_url_for_w_l;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 频道id
|
||||||
|
**/
|
||||||
|
public $platform_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 价格卖点
|
||||||
|
**/
|
||||||
|
public $price_usp_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 展示结束时间
|
||||||
|
**/
|
||||||
|
public $show_end_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始展示时间
|
||||||
|
**/
|
||||||
|
public $show_start_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 淘宝类目id
|
||||||
|
**/
|
||||||
|
public $tb_first_cat_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品标题
|
||||||
|
**/
|
||||||
|
public $title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 卖点描述
|
||||||
|
**/
|
||||||
|
public $usp_desc_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无线链接
|
||||||
|
**/
|
||||||
|
public $wap_url;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复购订单,仅适用于手淘拉新
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class OrderData
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 预估佣金
|
||||||
|
**/
|
||||||
|
public $commission;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收货时间
|
||||||
|
**/
|
||||||
|
public $confirm_receive_time;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单号
|
||||||
|
**/
|
||||||
|
public $order_no;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付时间
|
||||||
|
**/
|
||||||
|
public $pay_time;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PublisherOrderDto
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class OrderPage
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否还有下一页
|
||||||
|
**/
|
||||||
|
public $has_next;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否还有上一页
|
||||||
|
**/
|
||||||
|
public $has_pre;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页码
|
||||||
|
**/
|
||||||
|
public $page_no;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 页大小
|
||||||
|
**/
|
||||||
|
public $page_size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 位点字段,由调用方原样传递
|
||||||
|
**/
|
||||||
|
public $position_index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PublisherOrderDto
|
||||||
|
**/
|
||||||
|
public $results;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 真正的业务数据结构
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class PageResult
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pageNo
|
||||||
|
**/
|
||||||
|
public $page_no;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pageSize
|
||||||
|
**/
|
||||||
|
public $page_size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单列表
|
||||||
|
**/
|
||||||
|
public $results;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总值
|
||||||
|
**/
|
||||||
|
public $total_count;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回结果
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class PaginationResult
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前页码
|
||||||
|
**/
|
||||||
|
public $current_page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展属性
|
||||||
|
**/
|
||||||
|
public $extend;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品数据
|
||||||
|
**/
|
||||||
|
public $model_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误码
|
||||||
|
**/
|
||||||
|
public $msg_code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误信息
|
||||||
|
**/
|
||||||
|
public $msg_info;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一页大小
|
||||||
|
**/
|
||||||
|
public $page_size;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求是否成功
|
||||||
|
**/
|
||||||
|
public $success;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品总数
|
||||||
|
**/
|
||||||
|
public $total_item;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总页数
|
||||||
|
**/
|
||||||
|
public $total_page;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 埋点信息
|
||||||
|
**/
|
||||||
|
public $track_params;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权益扩展信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class PromotionExtend
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权益链接
|
||||||
|
**/
|
||||||
|
public $promotion_url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权益推荐商品
|
||||||
|
**/
|
||||||
|
public $recommend_item_list;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有价券信息
|
||||||
|
**/
|
||||||
|
public $youjia_coupon_info;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权益推荐商品
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class RecommendItemList
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权益推荐商品id
|
||||||
|
**/
|
||||||
|
public $item_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品链接
|
||||||
|
**/
|
||||||
|
public $url;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线下备案专属信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class RegisterInfoDto
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -经营类型
|
||||||
|
**/
|
||||||
|
public $career;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -对应的证件证件类型编号
|
||||||
|
**/
|
||||||
|
public $certify_number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -详细地址
|
||||||
|
**/
|
||||||
|
public $detail_address;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -地区
|
||||||
|
**/
|
||||||
|
public $location;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -手机号码
|
||||||
|
**/
|
||||||
|
public $phone_number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -证件类型
|
||||||
|
**/
|
||||||
|
public $shop_certify_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -店铺名称
|
||||||
|
**/
|
||||||
|
public $shop_name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道独有 -店铺类型
|
||||||
|
**/
|
||||||
|
public $shop_type;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Results
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data
|
||||||
|
**/
|
||||||
|
public $data;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道关系id的发放数据
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class RightsSendRelationRptDto
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期
|
||||||
|
**/
|
||||||
|
public $biz_date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红包发放数量
|
||||||
|
**/
|
||||||
|
public $fund_num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道关系id
|
||||||
|
**/
|
||||||
|
public $relation_id;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* model
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class RightsSendRptDTO
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渠道关系id的发放数据
|
||||||
|
**/
|
||||||
|
public $relation_rpt_list;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* model
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class TljInstanceReportDto
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引导成交金额
|
||||||
|
**/
|
||||||
|
public $alipay_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退款红包金额
|
||||||
|
**/
|
||||||
|
public $fp_refund_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退款红包个数
|
||||||
|
**/
|
||||||
|
public $fp_refund_num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引导预估佣金金额
|
||||||
|
**/
|
||||||
|
public $pre_commission_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失效回退金额
|
||||||
|
**/
|
||||||
|
public $refund_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失效回退红包个数
|
||||||
|
**/
|
||||||
|
public $refund_num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解冻金额
|
||||||
|
**/
|
||||||
|
public $unfreeze_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解冻红包个数
|
||||||
|
**/
|
||||||
|
public $unfreeze_num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红包核销金额
|
||||||
|
**/
|
||||||
|
public $use_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红包核销个数
|
||||||
|
**/
|
||||||
|
public $use_num;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红包领取金额
|
||||||
|
**/
|
||||||
|
public $win_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 红包领取个数
|
||||||
|
**/
|
||||||
|
public $win_num;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* results
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class TopDownloadRecordDo
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件创建时间
|
||||||
|
**/
|
||||||
|
public $created;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载链接状态。1:未下载。2:已下载
|
||||||
|
**/
|
||||||
|
public $status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载链接
|
||||||
|
**/
|
||||||
|
public $url;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 埋点信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Trackparams
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* empty
|
||||||
|
**/
|
||||||
|
public $empty;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品信息-商品关联词
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class WordMapData
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 链接-商品相关关联词落地页地址
|
||||||
|
**/
|
||||||
|
public $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品相关的关联词
|
||||||
|
**/
|
||||||
|
public $word;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有价券信息
|
||||||
|
* @author auto create
|
||||||
|
*/
|
||||||
|
class Youjiacouponinfo
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 有价券商品id
|
||||||
|
**/
|
||||||
|
public $item_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品链接
|
||||||
|
**/
|
||||||
|
public $url;
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
include "TopSdk.php";
|
||||||
|
date_default_timezone_set('Asia/Shanghai');
|
||||||
|
|
||||||
|
$c = new TopClient;
|
||||||
|
$c->appkey = '***********';
|
||||||
|
$c->secretKey = '*************************';
|
||||||
|
// $req = new TradeVoucherUploadRequest;
|
||||||
|
// $req->setFileName("example");
|
||||||
|
// $req->setFileData("@/Users/xt/Downloads/1.jpg");
|
||||||
|
// $req->setSellerNick("奥利奥官方旗舰店");
|
||||||
|
// $req->setBuyerNick("101NufynDYcbjf2cFQD123j8M/mjtyz6RoxQ2OL1c0e/Bcasdfasdasdfasdfas");
|
||||||
|
// var_dump($c->execute($req));
|
||||||
|
|
||||||
|
$req2 = new TradeVoucherUploadRequest;
|
||||||
|
$req2->setFileName("example");
|
||||||
|
|
||||||
|
$myPic = array(
|
||||||
|
'type' => 'application/octet-stream',
|
||||||
|
'content' => file_get_contents('/Users/xt/Downloads/1.jpg')
|
||||||
|
);
|
||||||
|
$req2->setFileData($myPic);
|
||||||
|
$req2->setSellerNick("奥利奥官方旗舰店");
|
||||||
|
$req2->setBuyerNick("101NufynDYcbjf2cFQD123j8M/mjtyz6RoxQ2OL1c0e/Bcasdfasdasdfasdfas");
|
||||||
|
var_dump($c->execute($req2));
|
||||||
|
?>
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.appip.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2020.08.28
|
||||||
|
*/
|
||||||
|
class AppipGetRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.appip.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.files.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.07.25
|
||||||
|
*/
|
||||||
|
class FilesGetRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 搜索结束时间
|
||||||
|
**/
|
||||||
|
private $endDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索开始时间
|
||||||
|
**/
|
||||||
|
private $startDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载链接状态。1:未下载。2:已下载
|
||||||
|
**/
|
||||||
|
private $status;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setEndDate($endDate)
|
||||||
|
{
|
||||||
|
$this->endDate = $endDate;
|
||||||
|
$this->apiParas["end_date"] = $endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEndDate()
|
||||||
|
{
|
||||||
|
return $this->endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStartDate($startDate)
|
||||||
|
{
|
||||||
|
$this->startDate = $startDate;
|
||||||
|
$this->apiParas["start_date"] = $startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStartDate()
|
||||||
|
{
|
||||||
|
return $this->startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status)
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
$this->apiParas["status"] = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.files.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->endDate,"endDate");
|
||||||
|
RequestCheckUtil::checkNotNull($this->startDate,"startDate");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.httpdns.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.07.25
|
||||||
|
*/
|
||||||
|
class HttpdnsGetRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.httpdns.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.ju.items.search request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.07.25
|
||||||
|
*/
|
||||||
|
class JuItemsSearchRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* query
|
||||||
|
**/
|
||||||
|
private $paramTopItemQuery;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setParamTopItemQuery($paramTopItemQuery)
|
||||||
|
{
|
||||||
|
$this->paramTopItemQuery = $paramTopItemQuery;
|
||||||
|
$this->apiParas["param_top_item_query"] = $paramTopItemQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParamTopItemQuery()
|
||||||
|
{
|
||||||
|
return $this->paramTopItemQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.ju.items.search";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.openuid.change request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.10.26
|
||||||
|
*/
|
||||||
|
class OpenuidChangeRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* openUid
|
||||||
|
**/
|
||||||
|
private $openUid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换到的appkey
|
||||||
|
**/
|
||||||
|
private $targetAppKey;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setOpenUid($openUid)
|
||||||
|
{
|
||||||
|
$this->openUid = $openUid;
|
||||||
|
$this->apiParas["open_uid"] = $openUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOpenUid()
|
||||||
|
{
|
||||||
|
return $this->openUid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTargetAppKey($targetAppKey)
|
||||||
|
{
|
||||||
|
$this->targetAppKey = $targetAppKey;
|
||||||
|
$this->apiParas["target_app_key"] = $targetAppKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTargetAppKey()
|
||||||
|
{
|
||||||
|
return $this->targetAppKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.openuid.change";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->openUid,"openUid");
|
||||||
|
RequestCheckUtil::checkNotNull($this->targetAppKey,"targetAppKey");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.openuid.get.bymixnick request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2019.10.21
|
||||||
|
*/
|
||||||
|
class OpenuidGetBymixnickRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 无线类应用获取到的混淆的nick
|
||||||
|
**/
|
||||||
|
private $mixNick;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setMixNick($mixNick)
|
||||||
|
{
|
||||||
|
$this->mixNick = $mixNick;
|
||||||
|
$this->apiParas["mix_nick"] = $mixNick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMixNick()
|
||||||
|
{
|
||||||
|
return $this->mixNick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.openuid.get.bymixnick";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->mixNick,"mixNick");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.openuid.get.bytrade request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.10.17
|
||||||
|
*/
|
||||||
|
class OpenuidGetBytradeRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 订单ID
|
||||||
|
**/
|
||||||
|
private $tid;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setTid($tid)
|
||||||
|
{
|
||||||
|
$this->tid = $tid;
|
||||||
|
$this->apiParas["tid"] = $tid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTid()
|
||||||
|
{
|
||||||
|
return $this->tid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.openuid.get.bytrade";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->tid,"tid");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.openuid.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.10.17
|
||||||
|
*/
|
||||||
|
class OpenuidGetRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.openuid.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.tbk.coupon.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2020.10.08
|
||||||
|
*/
|
||||||
|
class TbkCouponGetRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 券ID
|
||||||
|
**/
|
||||||
|
private $activityId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品ID
|
||||||
|
**/
|
||||||
|
private $itemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 带券ID与商品ID的加密串
|
||||||
|
**/
|
||||||
|
private $me;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setActivityId($activityId)
|
||||||
|
{
|
||||||
|
$this->activityId = $activityId;
|
||||||
|
$this->apiParas["activity_id"] = $activityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getActivityId()
|
||||||
|
{
|
||||||
|
return $this->activityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setItemId($itemId)
|
||||||
|
{
|
||||||
|
$this->itemId = $itemId;
|
||||||
|
$this->apiParas["item_id"] = $itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getItemId()
|
||||||
|
{
|
||||||
|
return $this->itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMe($me)
|
||||||
|
{
|
||||||
|
$this->me = $me;
|
||||||
|
$this->apiParas["me"] = $me;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMe()
|
||||||
|
{
|
||||||
|
return $this->me;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.tbk.coupon.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.tbk.dg.punish.order.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2019.11.10
|
||||||
|
*/
|
||||||
|
class TbkDgPunishOrderGetRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 入参的对象
|
||||||
|
**/
|
||||||
|
private $afOrderOption;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setAfOrderOption($afOrderOption)
|
||||||
|
{
|
||||||
|
$this->afOrderOption = $afOrderOption;
|
||||||
|
$this->apiParas["af_order_option"] = $afOrderOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAfOrderOption()
|
||||||
|
{
|
||||||
|
return $this->afOrderOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.tbk.dg.punish.order.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.tbk.dg.vegas.tlj.instance.report request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2020.07.09
|
||||||
|
*/
|
||||||
|
class TbkDgVegasTljInstanceReportRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 实例ID
|
||||||
|
**/
|
||||||
|
private $rightsId;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setRightsId($rightsId)
|
||||||
|
{
|
||||||
|
$this->rightsId = $rightsId;
|
||||||
|
$this->apiParas["rights_id"] = $rightsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRightsId()
|
||||||
|
{
|
||||||
|
return $this->rightsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.tbk.dg.vegas.tlj.instance.report";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->rightsId,"rightsId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.tbk.relation.refund request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2020.03.23
|
||||||
|
*/
|
||||||
|
class TbkRelationRefundRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 参数option
|
||||||
|
**/
|
||||||
|
private $searchOption;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setSearchOption($searchOption)
|
||||||
|
{
|
||||||
|
$this->searchOption = $searchOption;
|
||||||
|
$this->apiParas["search_option"] = $searchOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSearchOption()
|
||||||
|
{
|
||||||
|
return $this->searchOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.tbk.relation.refund";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.tbk.tpwd.create request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2020.10.08
|
||||||
|
*/
|
||||||
|
class TbkTpwdCreateRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* [已废弃]扩展字段JSON格式
|
||||||
|
**/
|
||||||
|
private $ext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 口令弹框logoURL
|
||||||
|
**/
|
||||||
|
private $logo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 口令弹框内容
|
||||||
|
**/
|
||||||
|
private $text;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 口令跳转目标页
|
||||||
|
**/
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成口令的淘宝用户ID
|
||||||
|
**/
|
||||||
|
private $userId;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setExt($ext)
|
||||||
|
{
|
||||||
|
$this->ext = $ext;
|
||||||
|
$this->apiParas["ext"] = $ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExt()
|
||||||
|
{
|
||||||
|
return $this->ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLogo($logo)
|
||||||
|
{
|
||||||
|
$this->logo = $logo;
|
||||||
|
$this->apiParas["logo"] = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLogo()
|
||||||
|
{
|
||||||
|
return $this->logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setText($text)
|
||||||
|
{
|
||||||
|
$this->text = $text;
|
||||||
|
$this->apiParas["text"] = $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getText()
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUrl($url)
|
||||||
|
{
|
||||||
|
$this->url = $url;
|
||||||
|
$this->apiParas["url"] = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUserId($userId)
|
||||||
|
{
|
||||||
|
$this->userId = $userId;
|
||||||
|
$this->apiParas["user_id"] = $userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUserId()
|
||||||
|
{
|
||||||
|
return $this->userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.tbk.tpwd.create";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->text,"text");
|
||||||
|
RequestCheckUtil::checkNotNull($this->url,"url");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.time.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.07.25
|
||||||
|
*/
|
||||||
|
class TimeGetRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.time.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.top.auth.token.refresh request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2019.11.26
|
||||||
|
*/
|
||||||
|
class TopAuthTokenRefreshRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* grantType==refresh_token 时需要
|
||||||
|
**/
|
||||||
|
private $refreshToken;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setRefreshToken($refreshToken)
|
||||||
|
{
|
||||||
|
$this->refreshToken = $refreshToken;
|
||||||
|
$this->apiParas["refresh_token"] = $refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRefreshToken()
|
||||||
|
{
|
||||||
|
return $this->refreshToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.top.auth.token.refresh";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->refreshToken,"refreshToken");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.top.ipout.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2018.08.07
|
||||||
|
*/
|
||||||
|
class TopIpoutGetRequest
|
||||||
|
{
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.top.ipout.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,80 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* TOP API: taobao.top.secret.get request
|
||||||
|
*
|
||||||
|
* @author auto create
|
||||||
|
* @since 1.0, 2019.11.07
|
||||||
|
*/
|
||||||
|
class TopSecretGetRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 自定义用户id
|
||||||
|
**/
|
||||||
|
private $customerUserId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 伪随机数
|
||||||
|
**/
|
||||||
|
private $randomNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 秘钥版本号
|
||||||
|
**/
|
||||||
|
private $secretVersion;
|
||||||
|
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function setCustomerUserId($customerUserId)
|
||||||
|
{
|
||||||
|
$this->customerUserId = $customerUserId;
|
||||||
|
$this->apiParas["customer_user_id"] = $customerUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCustomerUserId()
|
||||||
|
{
|
||||||
|
return $this->customerUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRandomNum($randomNum)
|
||||||
|
{
|
||||||
|
$this->randomNum = $randomNum;
|
||||||
|
$this->apiParas["random_num"] = $randomNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRandomNum()
|
||||||
|
{
|
||||||
|
return $this->randomNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSecretVersion($secretVersion)
|
||||||
|
{
|
||||||
|
$this->secretVersion = $secretVersion;
|
||||||
|
$this->apiParas["secret_version"] = $secretVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSecretVersion()
|
||||||
|
{
|
||||||
|
return $this->secretVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.top.secret.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check()
|
||||||
|
{
|
||||||
|
|
||||||
|
RequestCheckUtil::checkNotNull($this->randomNum,"randomNum");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
class Security {
|
||||||
|
|
||||||
|
private static $iv = "0102030405060708";
|
||||||
|
|
||||||
|
public static function encrypt($input, $key) {
|
||||||
|
$key = base64_decode($key);
|
||||||
|
$localIV = Security::$iv;
|
||||||
|
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
|
||||||
|
mcrypt_generic_init($module, $key, $localIV);
|
||||||
|
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
|
||||||
|
$input = Security::pkcs5_pad($input, $size);
|
||||||
|
$data = mcrypt_generic($module, $input);
|
||||||
|
|
||||||
|
mcrypt_generic_deinit($module);
|
||||||
|
mcrypt_module_close($module);
|
||||||
|
$data = base64_encode($data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function hmac_md5($input, $key) {
|
||||||
|
$key = base64_decode($key);
|
||||||
|
return hash_hmac('md5', $input, $key,true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function pkcs5_pad ($text, $blocksize) {
|
||||||
|
$pad = $blocksize - (strlen($text) % $blocksize);
|
||||||
|
return $text . str_repeat(chr($pad), $pad);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function decrypt($sStr, $key) {
|
||||||
|
$key = base64_decode($key);
|
||||||
|
$localIV = Security::$iv;
|
||||||
|
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
|
||||||
|
mcrypt_generic_init($module, $key, $localIV);
|
||||||
|
$encryptedData = base64_decode($sStr);
|
||||||
|
$encryptedData = mdecrypt_generic($module, $encryptedData);
|
||||||
|
|
||||||
|
$dec_s = strlen($encryptedData);
|
||||||
|
$padding = ord($encryptedData[$dec_s-1]);
|
||||||
|
$decrypted = substr($encryptedData, 0, -$padding);
|
||||||
|
|
||||||
|
mcrypt_generic_deinit($module);
|
||||||
|
mcrypt_module_close($module);
|
||||||
|
if(!$decrypted){
|
||||||
|
throw new Exception("Decrypt Error,Please Check SecretKey");
|
||||||
|
}
|
||||||
|
return $decrypted;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SecretContext
|
||||||
|
{
|
||||||
|
var $secret;
|
||||||
|
var $secretVersion;
|
||||||
|
var $invalidTime;
|
||||||
|
var $maxInvalidTime;
|
||||||
|
var $appConfig;
|
||||||
|
|
||||||
|
var $cacheKey = '';
|
||||||
|
var $session = '';
|
||||||
|
var $encryptPhoneNum = 0;
|
||||||
|
var $encryptNickNum = 0;
|
||||||
|
var $encryptReceiverNameNum = 0;
|
||||||
|
var $encryptSimpleNum = 0;
|
||||||
|
var $encryptSearchNum = 0;
|
||||||
|
|
||||||
|
var $decryptPhoneNum = 0;
|
||||||
|
var $decryptNickNum = 0;
|
||||||
|
var $decryptReceiverNameNum = 0;
|
||||||
|
var $decryptSimpleNum = 0;
|
||||||
|
var $decryptSearchNum = 0;
|
||||||
|
|
||||||
|
var $searchPhoneNum = 0;
|
||||||
|
var $searchNickNum = 0;
|
||||||
|
var $searchReceiverNameNum = 0;
|
||||||
|
var $searchSimpleNum = 0;
|
||||||
|
var $searchSearchNum = 0;
|
||||||
|
|
||||||
|
var $lastUploadTime;
|
||||||
|
|
||||||
|
function toLogString()
|
||||||
|
{
|
||||||
|
return $this->session.','.$this->encryptPhoneNum.','.$this->encryptNickNum.','
|
||||||
|
.$this->encryptReceiverNameNum.','.$this->encryptSimpleNum.','.$this->encryptSearchNum.','
|
||||||
|
.$this->decryptPhoneNum.','.$this->decryptNickNum.','.$this->decryptReceiverNameNum.','
|
||||||
|
.$this->decryptSimpleNum.','.$this->decryptSearchNum.','.$this->searchPhoneNum.','
|
||||||
|
.$this->searchNickNum.','.$this->searchReceiverNameNum.','.$this->searchSimpleNum.','
|
||||||
|
.$this->searchSearchNum ;
|
||||||
|
}
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->lastUploadTime = time();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SecretData
|
||||||
|
{
|
||||||
|
var $originalValue;
|
||||||
|
var $originalBase64Value;
|
||||||
|
var $secretVersion;
|
||||||
|
var $search;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class TopSecretGetRequest
|
||||||
|
{
|
||||||
|
private $apiParas = array();
|
||||||
|
|
||||||
|
public function getApiMethodName()
|
||||||
|
{
|
||||||
|
return "taobao.top.secret.get";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiParas()
|
||||||
|
{
|
||||||
|
return $this->apiParas;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRandomNum($random){
|
||||||
|
$this->apiParas['random_num'] = $random;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCustomerUserId($customId){
|
||||||
|
$this->apiParas['customer_user_id'] = $customId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSecretVersion($version){
|
||||||
|
$this->apiParas['secret_version'] = $version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check(){}
|
||||||
|
|
||||||
|
public function putOtherTextParam($key, $value) {
|
||||||
|
$this->apiParas[$key] = $value;
|
||||||
|
$this->$key = $value;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,589 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include './SecretContext.php';
|
||||||
|
include './MagicCrypt.php';
|
||||||
|
|
||||||
|
class SecurityUtil
|
||||||
|
{
|
||||||
|
|
||||||
|
private $BASE64_ARRAY = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
||||||
|
private $SEPARATOR_CHAR_MAP;
|
||||||
|
|
||||||
|
function __construct()
|
||||||
|
{
|
||||||
|
if(!defined("PHONE_SEPARATOR_CHAR"))
|
||||||
|
{
|
||||||
|
define('PHONE_SEPARATOR_CHAR','$');
|
||||||
|
}
|
||||||
|
if(!defined("NICK_SEPARATOR_CHAR"))
|
||||||
|
{
|
||||||
|
define('NICK_SEPARATOR_CHAR','~');
|
||||||
|
}
|
||||||
|
if(!defined("NORMAL_SEPARATOR_CHAR"))
|
||||||
|
{
|
||||||
|
define('NORMAL_SEPARATOR_CHAR',chr(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->SEPARATOR_CHAR_MAP['nick'] = NICK_SEPARATOR_CHAR;
|
||||||
|
$this->SEPARATOR_CHAR_MAP['simple'] = NICK_SEPARATOR_CHAR;
|
||||||
|
$this->SEPARATOR_CHAR_MAP['receiver_name'] = NICK_SEPARATOR_CHAR;
|
||||||
|
$this->SEPARATOR_CHAR_MAP['search'] = NICK_SEPARATOR_CHAR;
|
||||||
|
$this->SEPARATOR_CHAR_MAP['normal'] = NORMAL_SEPARATOR_CHAR;
|
||||||
|
$this->SEPARATOR_CHAR_MAP['phone'] = PHONE_SEPARATOR_CHAR;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 判断是否是base64格式的数据
|
||||||
|
*/
|
||||||
|
function isBase64Str($str)
|
||||||
|
{
|
||||||
|
$strLen = strlen($str);
|
||||||
|
for($i = 0; $i < $strLen ; $i++)
|
||||||
|
{
|
||||||
|
if(!$this->isBase64Char($str[$i]))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 判断是否是base64格式的字符
|
||||||
|
*/
|
||||||
|
function isBase64Char($char)
|
||||||
|
{
|
||||||
|
return strpos($this->BASE64_ARRAY,$char) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 使用sep字符进行trim
|
||||||
|
*/
|
||||||
|
function trimBySep($str,$sep)
|
||||||
|
{
|
||||||
|
$start = 0;
|
||||||
|
$end = strlen($str);
|
||||||
|
for($i = 0; $i < $end; $i++)
|
||||||
|
{
|
||||||
|
if($str[$i] == $sep)
|
||||||
|
{
|
||||||
|
$start = $i + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for($i = $end -1 ; $i >= 0; $i--)
|
||||||
|
{
|
||||||
|
if($str[$i] == $sep)
|
||||||
|
{
|
||||||
|
$end = $i - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return substr($str,$start,$end);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkEncryptData($dataArray)
|
||||||
|
{
|
||||||
|
if(count($dataArray) == 2){
|
||||||
|
return $this->isBase64Str($dataArray[0]);
|
||||||
|
}else{
|
||||||
|
return $this->isBase64Str($dataArray[0]) && $this->isBase64Str($dataArray[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 判断是否是加密数据
|
||||||
|
*/
|
||||||
|
function isEncryptDataArray($array,$type)
|
||||||
|
{
|
||||||
|
foreach ($array as $value) {
|
||||||
|
if(!$this->isEncryptData($value,$type)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否是已加密的数据,数据必须是同一个类型
|
||||||
|
*/
|
||||||
|
function isPartEncryptData($array,$type)
|
||||||
|
{
|
||||||
|
$result = false;
|
||||||
|
foreach ($array as $value) {
|
||||||
|
if($this->isEncryptData($value,$type)){
|
||||||
|
$result = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 判断是否是加密数据
|
||||||
|
*/
|
||||||
|
function isEncryptData($data,$type)
|
||||||
|
{
|
||||||
|
if(!is_string($data) || strlen($data) < 4)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$separator = $this->SEPARATOR_CHAR_MAP[$type];
|
||||||
|
$strlen = strlen($data);
|
||||||
|
if($data[0] != $separator || $data[$strlen -1] != $separator)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dataArray = explode($separator,$this->trimBySep($data,$separator));
|
||||||
|
$arrayLength = count($dataArray);
|
||||||
|
|
||||||
|
if($separator == PHONE_SEPARATOR_CHAR)
|
||||||
|
{
|
||||||
|
if($arrayLength != 3)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if($data[$strlen - 2] == $separator)
|
||||||
|
{
|
||||||
|
return $this->checkEncryptData($dataArray);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$version = $dataArray[$arrayLength -1];
|
||||||
|
if(is_numeric($version))
|
||||||
|
{
|
||||||
|
$base64Val = $dataArray[$arrayLength -2];
|
||||||
|
return $this->isBase64Str($base64Val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if($data[strlen($data) - 2] == $separator && $arrayLength == 3)
|
||||||
|
{
|
||||||
|
return $this->checkEncryptData($dataArray);
|
||||||
|
}
|
||||||
|
else if($arrayLength == 2)
|
||||||
|
{
|
||||||
|
return $this->checkEncryptData($dataArray);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function search($data, $type,$secretContext)
|
||||||
|
{
|
||||||
|
$separator = $this->SEPARATOR_CHAR_MAP[$type];
|
||||||
|
if('phone' == $type) {
|
||||||
|
if (strlen($data) != 4 ) {
|
||||||
|
throw new Exception("phoneNumber error");
|
||||||
|
}
|
||||||
|
return $separator.$this->hmacMD5EncryptToBase64($data, $secretContext->secret).$separator;
|
||||||
|
} else {
|
||||||
|
$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
|
||||||
|
$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
|
||||||
|
|
||||||
|
$slideList = $this->getSlideWindows($data, $slideSize);
|
||||||
|
$builder = '';
|
||||||
|
foreach ($slideList as $slide) {
|
||||||
|
$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
|
||||||
|
}
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 加密逻辑
|
||||||
|
*/
|
||||||
|
function encrypt($data,$type,$version,$secretContext)
|
||||||
|
{
|
||||||
|
if(!is_string($data))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$separator = $this->SEPARATOR_CHAR_MAP[$type];
|
||||||
|
$isIndexEncrypt = $this->isIndexEncrypt($type,$version,$secretContext);
|
||||||
|
if($isIndexEncrypt || $type == "search"){
|
||||||
|
if('phone' == $type) {
|
||||||
|
return $this->encryptPhoneIndex($data,$separator,$secretContext);
|
||||||
|
} else {
|
||||||
|
$compressLen = $this->getArrayValue($secretContext->appConfig,'encrypt_index_compress_len',3);
|
||||||
|
$slideSize = $this->getArrayValue($secretContext->appConfig,'encrypt_slide_size',4);
|
||||||
|
return $this->encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if('phone' == $type) {
|
||||||
|
return $this->encryptPhone($data,$separator,$secretContext);
|
||||||
|
} else {
|
||||||
|
return $this->encryptNormal($data,$separator,$secretContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 加密逻辑,手机号码格式
|
||||||
|
*/
|
||||||
|
function encryptPhone($data,$separator,$secretContext)
|
||||||
|
{
|
||||||
|
$len = strlen($data);
|
||||||
|
if($len < 11)
|
||||||
|
{
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
$prefixNumber = substr($data,0,$len -8);
|
||||||
|
$last8Number = substr($data,$len -8,$len);
|
||||||
|
|
||||||
|
return $separator.$prefixNumber.$separator.Security::encrypt($last8Number,$secretContext->secret)
|
||||||
|
.$separator.$secretContext->secretVersion.$separator ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 加密逻辑,非手机号码格式
|
||||||
|
*/
|
||||||
|
function encryptNormal($data,$separator,$secretContext)
|
||||||
|
{
|
||||||
|
return $separator.Security::encrypt($data,$secretContext->secret)
|
||||||
|
.$separator.$secretContext->secretVersion.$separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 解密逻辑
|
||||||
|
*/
|
||||||
|
function decrypt($data,$type,$secretContext)
|
||||||
|
{
|
||||||
|
if(!$this->isEncryptData($data,$type))
|
||||||
|
{
|
||||||
|
throw new Exception("数据[".$data."]不是类型为[".$type."]的加密数据");
|
||||||
|
}
|
||||||
|
$dataLen = strlen($data);
|
||||||
|
$separator = $this->SEPARATOR_CHAR_MAP[$type];
|
||||||
|
|
||||||
|
$secretData = null;
|
||||||
|
if($data[$dataLen - 2] == $separator){
|
||||||
|
$secretData = $this->getIndexSecretData($data,$separator);
|
||||||
|
}else{
|
||||||
|
$secretData = $this->getSecretData($data,$separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($secretData == null){
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = Security::decrypt($secretData->originalBase64Value,$secretContext->secret);
|
||||||
|
|
||||||
|
if($separator == PHONE_SEPARATOR_CHAR && !$secretData->search)
|
||||||
|
{
|
||||||
|
return $secretData->originalValue.$result;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 判断是否是公钥数据
|
||||||
|
*/
|
||||||
|
function isPublicData($data,$type)
|
||||||
|
{
|
||||||
|
$secretData = $this->getSecretDataByType($data,$type);
|
||||||
|
if(empty($secretData)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(intval($secretData->secretVersion) < 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSecretDataByType($data,$type)
|
||||||
|
{
|
||||||
|
$separator = $this->SEPARATOR_CHAR_MAP[$type];
|
||||||
|
$dataLen = strlen($data);
|
||||||
|
|
||||||
|
if($data[$dataLen - 2] == $separator){
|
||||||
|
return $secretData = $this->getIndexSecretData($data,$separator);
|
||||||
|
}else{
|
||||||
|
return $secretData = $this->getSecretData($data,$separator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 分解密文
|
||||||
|
*/
|
||||||
|
function getSecretData($data,$separator)
|
||||||
|
{
|
||||||
|
$secretData = new SecretData;
|
||||||
|
$dataArray = explode($separator,$this->trimBySep($data,$separator));
|
||||||
|
$arrayLength = count($dataArray);
|
||||||
|
|
||||||
|
if($separator == PHONE_SEPARATOR_CHAR)
|
||||||
|
{
|
||||||
|
if($arrayLength != 3){
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
$version = $dataArray[2];
|
||||||
|
if(is_numeric($version))
|
||||||
|
{
|
||||||
|
$secretData->originalValue = $dataArray[0];
|
||||||
|
$secretData->originalBase64Value = $dataArray[1];
|
||||||
|
$secretData->secretVersion = $version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($arrayLength != 2){
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
$version = $dataArray[1];
|
||||||
|
if(is_numeric($version))
|
||||||
|
{
|
||||||
|
$secretData->originalBase64Value = $dataArray[0];
|
||||||
|
$secretData->secretVersion = $version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $secretData;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getIndexSecretData($data,$separator) {
|
||||||
|
$secretData = new SecretData;
|
||||||
|
$dataArray = explode($separator,$this->trimBySep($data,$separator));
|
||||||
|
$arrayLength = count($dataArray);
|
||||||
|
|
||||||
|
if($separator == PHONE_SEPARATOR_CHAR) {
|
||||||
|
if ($arrayLength != 3) {
|
||||||
|
return null;
|
||||||
|
}else{
|
||||||
|
$version = $dataArray[2];
|
||||||
|
if(is_numeric($version))
|
||||||
|
{
|
||||||
|
$secretData->originalValue = $dataArray[0];
|
||||||
|
$secretData->originalBase64Value = $dataArray[1];
|
||||||
|
$secretData->secretVersion = $version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if($arrayLength != 3){
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
$version = $dataArray[2];
|
||||||
|
if(is_numeric($version))
|
||||||
|
{
|
||||||
|
$secretData->originalBase64Value = $dataArray[0];
|
||||||
|
$secretData->originalValue = $dataArray[1];
|
||||||
|
$secretData->secretVersion = $version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$secretData->search = true;
|
||||||
|
return $secretData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断密文是否支持检索
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @param version
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
function isIndexEncrypt($key,$version,$secretContext)
|
||||||
|
{
|
||||||
|
if ($version != null && $version < 0) {
|
||||||
|
$key = "previous_".$key;
|
||||||
|
} else {
|
||||||
|
$key = "current_".$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $secretContext->appConfig != null &&
|
||||||
|
array_key_exists($key,$secretContext->appConfig) &&
|
||||||
|
$secretContext->appConfig[$key] == "2";
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLetterOrDigit($ch)
|
||||||
|
{
|
||||||
|
$code = ord($ch);
|
||||||
|
if (0 <= $code && $code <= 127) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function utf8_strlen($string = null) {
|
||||||
|
// 将字符串分解为单元
|
||||||
|
preg_match_all("/./us", $string, $match);
|
||||||
|
// 返回单元个数
|
||||||
|
return count($match[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function utf8_substr($string,$start,$end) {
|
||||||
|
// 将字符串分解为单元
|
||||||
|
preg_match_all("/./us", $string, $match);
|
||||||
|
// 返回单元个数
|
||||||
|
$result = "";
|
||||||
|
for($i = $start; $i < $end; $i++){
|
||||||
|
$result .= $match[0][$i];
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function utf8_str_at($string,$index) {
|
||||||
|
// 将字符串分解为单元
|
||||||
|
preg_match_all("/./us", $string, $match);
|
||||||
|
// 返回单元个数
|
||||||
|
return $match[0][$index];
|
||||||
|
}
|
||||||
|
|
||||||
|
function compress($input,$toLength) {
|
||||||
|
if($toLength < 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$output = array();
|
||||||
|
for($i = 0; $i < $toLength; $i++) {
|
||||||
|
$output[$i] = chr(0);
|
||||||
|
}
|
||||||
|
$input = $this->getBytes($input);
|
||||||
|
$inputLength = count($input);
|
||||||
|
for ($i = 0; $i < $inputLength; $i++) {
|
||||||
|
$index_output = $i % $toLength;
|
||||||
|
$output[$index_output] = $output[$index_output] ^ $input[$i];
|
||||||
|
}
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #hmacMD5Encrypt
|
||||||
|
*
|
||||||
|
* @param encryptText
|
||||||
|
* 被签名的字符串
|
||||||
|
* @param encryptKey
|
||||||
|
* 密钥
|
||||||
|
* @param compressLen压缩长度
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
function hmacMD5EncryptToBase64($encryptText,$encryptKey,$compressLen = 0) {
|
||||||
|
$encryptResult = Security::hmac_md5($encryptText,$encryptKey);
|
||||||
|
if($compressLen != 0){
|
||||||
|
$encryptResult = $this->compress($encryptResult,$compressLen);
|
||||||
|
}
|
||||||
|
return base64_encode($this->toStr($encryptResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成滑动窗口
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* @param slideSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
function getSlideWindows($input,$slideSize = 4)
|
||||||
|
{
|
||||||
|
$endIndex = 0;
|
||||||
|
$startIndex = 0;
|
||||||
|
$currentWindowSize = 0;
|
||||||
|
$currentWindow = null;
|
||||||
|
$dataLength = $this->utf8_strlen($input);
|
||||||
|
$windows = array();
|
||||||
|
while($endIndex < $dataLength || $currentWindowSize > $slideSize)
|
||||||
|
{
|
||||||
|
$startsWithLetterOrDigit = false;
|
||||||
|
if(!empty($currentWindow)){
|
||||||
|
$startsWithLetterOrDigit = $this->isLetterOrDigit($this->utf8_str_at($currentWindow,0));
|
||||||
|
}
|
||||||
|
if($endIndex == $dataLength && $startsWithLetterOrDigit == false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if($currentWindowSize == $slideSize &&
|
||||||
|
$startsWithLetterOrDigit == false &&
|
||||||
|
$this->isLetterOrDigit($this->utf8_str_at($input,$endIndex))) {
|
||||||
|
$endIndex ++;
|
||||||
|
$currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
|
||||||
|
$currentWindowSize = 5;
|
||||||
|
} else {
|
||||||
|
if($endIndex != 0){
|
||||||
|
if($startsWithLetterOrDigit){
|
||||||
|
$currentWindowSize -= 1;
|
||||||
|
}else{
|
||||||
|
$currentWindowSize -= 2;
|
||||||
|
}
|
||||||
|
$startIndex ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($currentWindowSize < $slideSize && $endIndex < $dataLength) {
|
||||||
|
$currentChar = $this->utf8_str_at($input,$endIndex);
|
||||||
|
if ($this->isLetterOrDigit($currentChar)) {
|
||||||
|
$currentWindowSize += 1;
|
||||||
|
} else {
|
||||||
|
$currentWindowSize += 2;
|
||||||
|
}
|
||||||
|
$endIndex++;
|
||||||
|
}
|
||||||
|
$currentWindow = $this->utf8_substr($input,$startIndex,$endIndex);
|
||||||
|
}
|
||||||
|
array_push($windows,$currentWindow);
|
||||||
|
}
|
||||||
|
return $windows;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encryptPhoneIndex($data,$separator,$secretContext) {
|
||||||
|
$dataLength = strlen($data);
|
||||||
|
if($dataLength < 11) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
$last4Number = substr($data,$dataLength -4 ,$dataLength);
|
||||||
|
return $separator.$this->hmacMD5EncryptToBase64($last4Number,$secretContext->secret).$separator
|
||||||
|
.Security::encrypt($data,$secretContext->secret).$separator.$secretContext->secretVersion
|
||||||
|
.$separator.$separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
function encryptNormalIndex($data,$compressLen,$slideSize,$separator,$secretContext) {
|
||||||
|
$slideList = $this->getSlideWindows($data, $slideSize);
|
||||||
|
$builder = "";
|
||||||
|
foreach ($slideList as $slide) {
|
||||||
|
$builder .= $this->hmacMD5EncryptToBase64($slide,$secretContext->secret,$compressLen);
|
||||||
|
}
|
||||||
|
return $separator.Security::encrypt($data,$secretContext->secret).$separator.$builder.$separator
|
||||||
|
.$secretContext->secretVersion.$separator.$separator;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getArrayValue($array,$key,$default) {
|
||||||
|
if(array_key_exists($key, $array)){
|
||||||
|
return $array[$key];
|
||||||
|
}
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getBytes($string) {
|
||||||
|
$bytes = array();
|
||||||
|
for($i = 0; $i < strlen($string); $i++){
|
||||||
|
$bytes[] = ord($string[$i]);
|
||||||
|
}
|
||||||
|
return $bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function toStr($bytes) {
|
||||||
|
if(!is_array($bytes)){
|
||||||
|
return $bytes;
|
||||||
|
}
|
||||||
|
$str = '';
|
||||||
|
foreach($bytes as $ch) {
|
||||||
|
$str .= chr($ch);
|
||||||
|
}
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue