From e46d347a0dc3b50f9d7434c632a9eda7dbeda0e6 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Fri, 30 Jun 2017 13:55:28 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E5=8F=98=E6=9B=B4=E8=87=AA=E5=B8=A6?= =?UTF-8?q?=E4=B8=89=E6=96=B9SDK=EF=BC=8C=E9=BB=98=E8=AE=A4=E6=94=AF?= =?UTF-8?q?=E6=8C=81ApiAdmin=E7=9A=84=E4=BA=92=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/ApiStore/ApiAdminSDK.class.php | 78 +++ .../ApiSDK/ApiAdmin/AuthSign.class.php | 62 +++ .../ApiStore/ApiSDK/ApiAdmin/Http.class.php | 77 +++ .../ApiStore/ApiSDK/JPush/Config.class.php | 55 --- .../ApiStore/ApiSDK/JPush/Device.class.php | 13 - .../Home/ApiStore/ApiSDK/JPush/Http.class.php | 146 ------ .../Home/ApiStore/ApiSDK/JPush/Push.class.php | 443 ------------------ .../ApiStore/ApiSDK/JPush/Report.class.php | 13 - .../ApiStore/ApiSDK/JPush/Schedule.class.php | 13 - .../Home/ApiStore/ApiSDK/JPushSDK.class.php | 33 -- .../ApiStore/ApiSDK/TaoBao/AuthSign.class.php | 31 -- .../ApiStore/ApiSDK/TaoBao/Http.class.php | 38 -- .../Home/ApiStore/ApiSDK/TaoBaoSDK.class.php | 70 --- Application/Home/ApiStore/DayuSms.class.php | 39 -- 14 files changed, 217 insertions(+), 894 deletions(-) create mode 100644 Application/Home/ApiStore/ApiAdminSDK.class.php create mode 100644 Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php create mode 100644 Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Config.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Device.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Http.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Push.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Report.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPush/Schedule.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/JPushSDK.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/TaoBao/AuthSign.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/TaoBao/Http.class.php delete mode 100644 Application/Home/ApiStore/ApiSDK/TaoBaoSDK.class.php delete mode 100644 Application/Home/ApiStore/DayuSms.class.php diff --git a/Application/Home/ApiStore/ApiAdminSDK.class.php b/Application/Home/ApiStore/ApiAdminSDK.class.php new file mode 100644 index 0000000..2a3ae4f --- /dev/null +++ b/Application/Home/ApiStore/ApiAdminSDK.class.php @@ -0,0 +1,78 @@ + + */ + +namespace Home\ApiStore\ApiSDK; + + +use Home\ApiStore\ApiSDK\ApiAdmin\AuthSign; +use Home\ApiStore\ApiSDK\ApiAdmin\Http; + +class ApiAdminSDK { + private $method; //接口名称 + private $baseUrl = 'http://tadmin.365jxj.com/api/'; + private $accessTokenHash = '5937719b95405'; + private $version = 'v2.0'; + private $appInfo = array(); + + /** + * ApiAdminSDK constructor. + * @param string $method 接口名称 + * @param string $appInfo 应用信息 + */ + public function __construct($method, $appInfo) { + $this->method = $method; + $this->appInfo = $appInfo; + } + + public function updateAccessToken() { + $cacheKey = $this->appInfo['appId'] . '_access_token'; + S($cacheKey, null); + } + + public function getHeader($userToken = '') { + $signObj = new AuthSign($this->version, $this->appInfo); + $accessToken = $this->getAccessToken(); + + return $signObj->getHeader($accessToken, $userToken); + } + + public function getAccessToken() { + $cacheKey = $this->appInfo['appId'] . '_access_token'; + $accessToken = S($cacheKey); + if (!$accessToken) { + $signObj = new AuthSign($this->version, $this->appInfo); + $data = $signObj->getAccessTokenData(); + $queryStr = http_build_query($data); + $url = $this->baseUrl . $this->accessTokenHash . '?' . $queryStr; + $header = $signObj->getHeader(); + $returnArr = Http::get($url, $header); + if($returnArr['code'] == 1){ + $accessToken = $returnArr['data']['access_token']; + S($cacheKey, $accessToken, 7000); + } + } + + return $accessToken; + } + + /** + * 处理URL,当需要GET请求,请传入GET参数数组 + * @param $data + * @author zhaoxiang + * @return string + */ + public function buildUrl($data = array()) { + if ($data) { + $queryStr = '?'; + $queryStr .= http_build_query($data); + } else { + $queryStr = ''; + } + + return $this->baseUrl . $this->method . $queryStr; + } +} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php b/Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php new file mode 100644 index 0000000..4b911f8 --- /dev/null +++ b/Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php @@ -0,0 +1,62 @@ + + */ +class AuthSign { + + private $version; + private $appInfo; + + public function __construct($version, $appInfo) { + $this->version = $version; + $this->appInfo = $appInfo; + } + + public function getHeader($accessToken = '', $userToken = false) { + $header['version'] = $this->version; + if ($accessToken) { + $header['access-token'] = $accessToken; + } + $city = cookie('365jxj_city'); + if ($city) { + $header['city'] = $city; + } else { + $header['city'] = 'nj'; + } + if ($userToken) { + $header['user-token'] = $userToken; + } + + return $header; + } + + public function getAccessTokenData() { + $data['app_id'] = $this->appInfo['appId']; + $data['app_secret'] = $this->appInfo['appSecret']; + $data['device_id'] = 'zuAdmin'; + $data['rand_str'] = md5(rand(1, 10000) . microtime()); + $data['timestamp'] = time(); + $sign = $this->getSignature($data); + $data['signature'] = $sign; + + return $data; + } + + /** + * 获取身份秘钥 + * @param array $data + * @author zhaoxiang + * @return string + */ + private function getSignature($data) { + ksort($data); + $preStr = http_build_query($data); + + return md5($preStr); + } + +} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php b/Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php new file mode 100644 index 0000000..6a1afb6 --- /dev/null +++ b/Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php @@ -0,0 +1,77 @@ + + */ + +namespace Home\ApiStore\ApiSDK\ApiAdmin; + + +use Home\ORG\ReturnCode; + +class Http { + + public static function get($url, $header = array()) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FAILONERROR, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + if($header){ + $newHeader = array(); + foreach ($header as $key => $item) { + $newHeader[] = $key.':'.$item; + } + curl_setopt($ch, CURLOPT_HTTPHEADER, $newHeader); + } + + if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + $response = curl_exec($ch); + + if (curl_errno($ch)) { + E(curl_error($ch), ReturnCode::CURL_ERROR); + } + curl_close($ch); + $resArr = json_decode($response, true); + + return $resArr; + } + + public static function post($url, $header = array(), $body = array()) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_FAILONERROR, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + if($header){ + $newHeader = array(); + foreach ($header as $key => $item) { + $newHeader[] = $key.':'.$item; + } + curl_setopt($ch, CURLOPT_HTTPHEADER, $newHeader); + } + + if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + } + + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($body)); + + $response = curl_exec($ch); + + if (curl_errno($ch)) { + E(curl_error($ch), ReturnCode::CURL_ERROR); + } + curl_close($ch); + $resArr = json_decode($response, true); + + return $resArr; + } + +} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Config.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Config.class.php deleted file mode 100644 index 53adeea..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Config.class.php +++ /dev/null @@ -1,55 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -class Config { - - const APP_KEY = '884fc6fb9fb466e11def006a'; - const MASTER_SECRET = '11c72c7fad4110472a688973'; - - //推送API - const API_PUSH = 'https://api.jpush.cn/v3/push'; - //推送校验 API - const API_VALIDATE = 'https://api.jpush.cn/v3/push/validate'; - //送达统计 - const API_RECEIVED = 'https://report.jpush.cn/v3/received'; - //消息统计 - const API_MESSAGE = 'https://report.jpush.cn/v3/messages'; - //用户统计 - const API_USERS = 'https://report.jpush.cn/v3/users'; - //查询设备的别名与标签(设置设备的别名与标签) - const API_DEVICES = 'https://device.jpush.cn/v3/devices'; - //查询别名(删除别名) - const API_ALIASES = 'https://device.jpush.cn/v3/aliases'; - //查询标签列表(判断设备与标签绑定关系/更新标签/删除标签) - const API_TAG = 'https://device.jpush.cn/v3/tags'; - //获取用户在线状态 - const API_STATUS = 'https://device.jpush.cn/v3/devices/status/'; - //定时任务相关 - const API_SCHEDULES = 'https://api.jpush.cn/v3/schedules'; - - const HTTP_POST = 1; - const HTTP_GET = 2; - const HTTP_PUT = 3; - const HTTP_DELETE = 4; - - const PLATFORM_ANDROID = 'android'; - const PLATFORM_IOS = 'ios'; - - const DISABLE_SOUND = "_disable_Sound"; - const DISABLE_BADGE = 0x10000; - const USER_AGENT = 'JPush-API-PHP-Client'; - const CONNECT_TIMEOUT = 1; - //请求最长耗时 - const READ_TIMEOUT = 120; - //重连次数 - const DEFAULT_MAX_RETRY_TIMES = 3; - const DEFAULT_LOG_FILE = "./jpush.log"; - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Device.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Device.class.php deleted file mode 100644 index df71e88..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Device.class.php +++ /dev/null @@ -1,13 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -class Device { - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Http.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Http.class.php deleted file mode 100644 index 10ff634..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Http.class.php +++ /dev/null @@ -1,146 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -use Home\ORG\Response; -use Home\ORG\ReturnCode; - -class Http { - - public static function get($url) { - $response = self::sendRequest($url, Config::HTTP_GET, $body = null); - - return self::processResp($response); - } - - public static function post($url, $body) { - $response = self::sendRequest($url, Config::HTTP_POST, $body); - - return self::processResp($response); - } - - public static function put($url, $body) { - $response = self::sendRequest($url, Config::HTTP_PUT, $body); - - return self::processResp($response); - } - - public static function delete($url) { - $response = self::sendRequest($url, Config::HTTP_DELETE, $body = null); - - return self::processResp($response); - } - - private static function sendRequest($url, $method, $body = null, $times = 1) { - if (!defined('CURL_HTTP_VERSION_2_0')) { - define('CURL_HTTP_VERSION_2_0', 3); - } - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_USERAGENT, Config::USER_AGENT); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, Config::CONNECT_TIMEOUT); - curl_setopt($ch, CURLOPT_TIMEOUT, Config::READ_TIMEOUT); // 请求最长耗时 - // 设置SSL版本 1=CURL_SSLVERSION_TLSv1, 不指定使用默认值,curl会自动获取需要使用的CURL版本 - // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - // 如果报证书相关失败,可以考虑取消注释掉该行,强制指定证书版本 - //curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1'); - - // 设置Basic认证 - curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($ch, CURLOPT_USERPWD, Config::APP_KEY . ':' . Config::MASTER_SECRET); - curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0); - - // 设置Post参数 - switch ($method) { - case Config::HTTP_POST: - curl_setopt($ch, CURLOPT_POST, true); - break; - case Config::HTTP_DELETE: - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - break; - case Config::HTTP_PUT: - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - break; - } - - if (!is_null($body)) { - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); - } - curl_setopt($ch, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/json', - 'Connection: Keep-Alive' - )); - - $output = curl_exec($ch); - $response = array(); - $errorCode = curl_errno($ch); - - $msg = ''; - if (isset($body['options']['sendno'])) { - $sendNo = $body['options']['sendno']; - $msg = 'sendno: ' . $sendNo; - } - - - if ($errorCode) { - if ($times < Config::DEFAULT_MAX_RETRY_TIMES) { - return self::sendRequest($url, $method, $body, ++$times); - } else { - if ($errorCode === 28) { - Response::error(ReturnCode::CURL_ERROR, $msg . "Response timeout. Your request has probably be received by JPush Server,please check that whether need to be pushed again."); - } elseif ($errorCode === 56) { - Response::error(ReturnCode::CURL_ERROR, $msg . "Response timeout, maybe cause by old CURL version. Your request has probably be received by JPush Server, please check that whether need to be pushed again."); - } else { - Response::error(ReturnCode::CURL_ERROR, $msg . "Connect timeout, Please retry later. Error:" . $errorCode . " " . curl_error($ch)); - } - } - } else { - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); - $headerText = substr($output, 0, $headerSize); - $body = substr($output, $headerSize); - $headers = array(); - foreach (explode("\r\n", $headerText) as $i => $line) { - if (!empty($line)) { - if ($i === 0) { - $headers[0] = $line; - } else if (strpos($line, ": ")) { - list ($key, $value) = explode(': ', $line); - $headers[$key] = $value; - } - } - } - $response['headers'] = $headers; - $response['body'] = $body; - $response['httpCode'] = $httpCode; - } - curl_close($ch); - - return $response; - } - - public static function processResp($response) { - $data = json_decode($response['body'], true); - - if (is_null($data)) { - Response::error(ReturnCode::CURL_ERROR, '未收到返回数据'); - } elseif ($response['httpCode'] === 200) { - $result = array(); - $result['body'] = $data; - $result['httpCode'] = $response['httpCode']; - $result['headers'] = $response['headers']; - - return $result; - } - } - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Push.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Push.class.php deleted file mode 100644 index 69b53e3..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Push.class.php +++ /dev/null @@ -1,443 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -use Home\ORG\Response; -use Home\ORG\ReturnCode; - -class Push { - private $platform = 'all'; - private $tag = null; - private $tagAnd = null; - private $alias = null; - private $registrationId = null; - private $extras = null; - private $notificationAlert = null; - private $androidNotification = null; - private $iosNotification = null; - private $message = null; - private $options = null; - - /** - * 增加推送到苹果 - * @author zhaoxiang - * @return $this - */ - public function ios() { - if (is_array($this->platform)) { - if (!in_array(Config::PLATFORM_IOS, $this->platform)) { - array_push($this->platform, Config::PLATFORM_IOS); - } - } else { - $this->platform = array(Config::PLATFORM_IOS); - } - - return $this; - } - - /** - * 推送至安卓 - * @author zhaoxiang - * @return $this - */ - public function android() { - if (is_array($this->platform)) { - if (!in_array(Config::PLATFORM_ANDROID, $this->platform)) { - array_push($this->platform, Config::PLATFORM_ANDROID); - } - } else { - $this->platform = array(Config::PLATFORM_ANDROID); - } - - return $this; - } - - /** - * 设置推送tag,仅允许传入字符串和一维索引数组 - * @param string|array $param - * @author zhaoxiang - * @return $this - */ - public function addTag($param) { - if (is_null($this->tag)) { - if (is_array($this->tag)) { - $this->tag = $param; - } else { - $this->tag = array($param); - } - } else { - if (is_array($param)) { - foreach ($param as $item) { - if (!in_array($item, $this->tag)) { - array_push($this->tag, $item); - } - } - } else { - if (!in_array($param, $this->tag)) { - array_push($this->tag, $param); - } - } - } - - return $this; - } - - /** - * 设置推送tag_and,仅允许传入字符串和一维索引数组 - * @param string|array $param - * @author zhaoxiang - * @return $this - */ - public function addTagAnd($param) { - if (is_null($this->tagAnd)) { - if (is_array($this->tagAnd)) { - $this->tagAnd = $param; - } else { - $this->tagAnd = array($param); - } - } else { - if (is_array($param)) { - foreach ($param as $item) { - if (!in_array($item, $this->tagAnd)) { - array_push($this->tagAnd, $item); - } - } - } else { - if (!in_array($param, $this->tagAnd)) { - array_push($this->tagAnd, $param); - } - } - } - - return $this; - } - - /** - * 设置推送alias,仅允许传入字符串和一维索引数组 - * @param string|array $param - * @author zhaoxiang - * @return $this - */ - public function addAlias($param) { - if (is_null($this->alias)) { - if (is_array($this->alias)) { - $this->alias = $param; - } else { - $this->alias = array($param); - } - } else { - if (is_array($param)) { - foreach ($param as $item) { - if (!in_array($item, $this->alias)) { - array_push($this->alias, $item); - } - } - } else { - if (!in_array($param, $this->alias)) { - array_push($this->alias, $param); - } - } - } - - return $this; - } - - /** - * 设置推送registration_id,仅允许传入字符串和一维索引数组 - * @param string|array $param - * @author zhaoxiang - * @return $this - */ - public function addRegistrationId($param) { - if (is_null($this->registrationId)) { - if (is_array($this->registrationId)) { - $this->registrationId = $param; - } else { - $this->registrationId = array($param); - } - } else { - if (is_array($param)) { - foreach ($param as $item) { - if (!in_array($item, $this->registrationId)) { - array_push($this->registrationId, $item); - } - } - } else { - if (!in_array($param, $this->registrationId)) { - array_push($this->registrationId, $param); - } - } - } - - return $this; - } - - /** - * 设置公告消息 - * @param string $param - * @author zhaoxiang - * @return $this - */ - public function setNotificationAlert($param) { - if (!is_string($param)) { - Response::error(ReturnCode::EXCEPTION, 'NotificationAlert 必须是字符串'); - } - $this->notificationAlert = $param; - - return $this; - } - - /** - * 设置推送addExtras,新增加额外字段 - * @param array $param - * @author zhaoxiang - * @return $this - */ - public function addExtras($param) { - if (is_null($this->extras)) { - if (is_array($param)) { - $this->extras = $param; - } - } else { - if (is_array($param)) { - array_merge($this->extras, $param); - } - } - - return $this; - } - - /** - * 设置IOS的通知消息体 - * @param $alert - * @param array $notification - * @author zhaoxiang - * @return $this - */ - public function iosNotification($alert = null, $notification = array()) { - $ios = array(); - if (!is_null($alert)) { - $ios['alert'] = (is_string($alert) || is_array($alert)) ? $alert : ''; - } - if (!empty($notification)) { - if (isset($notification['sound']) && is_string($notification['sound'])) { - $ios['sound'] = $notification['sound']; - } - if (isset($notification['badge'])) { - $ios['badge'] = (int)$notification['badge'] ? $notification['badge'] : 0; - } - if (isset($notification['content-available']) && is_bool($notification['content-available']) && $notification['content-available']) { - $ios['content-available'] = $notification['content-available']; - } - if (isset($notification['mutable-content']) && is_bool($notification['mutable-content']) && $notification['mutable-content']) { - $ios['mutable-content'] = $notification['mutable-content']; - } - if (isset($notification['category']) && is_string($notification['category'])) { - $ios['category'] = $notification['category']; - } - if (isset($notification['extras']) && is_array($notification['extras']) && !empty($notification['extras'])) { - $ios['extras'] = $notification['extras']; - } - } - if (!isset($ios['sound'])) { - $ios['sound'] = ''; - } - if (!isset($ios['badge'])) { - $ios['badge'] = '+1'; - } - $this->iosNotification = $ios; - - return $this; - } - - /** - * 设置Android的通知消息体 - * @param $alert - * @param array $notification - * @author zhaoxiang - * @return $this - */ - public function androidNotification($alert = null, array $notification = array()) { - $android = array(); - if (!is_null($alert)) { - $android['alert'] = is_string($alert) ? $alert : ''; - } - if (!empty($notification)) { - if (isset($notification['title']) && is_string($notification['title'])) { - $android['title'] = $notification['title']; - } - if (isset($notification['builder_id']) && is_int($notification['builder_id'])) { - $android['builder_id'] = $notification['builder_id']; - } - if (isset($notification['extras']) && is_array($notification['extras']) && !empty($notification['extras'])) { - $android['extras'] = $notification['extras']; - } - if (isset($notification['priority']) && is_int($notification['priority'])) { - $android['priority'] = $notification['priority']; - } - if (isset($notification['category']) && is_string($notification['category'])) { - $android['category'] = $notification['category`']; - } - if (isset($notification['style']) && is_int($notification['style'])) { - $android['style'] = $notification['style']; - } - if (isset($notification['big_text']) && is_string($notification['big_text'])) { - $android['big_text'] = $notification['big_text']; - } - if (isset($notification['inbox']) && is_array($notification['inbox'])) { - $android['inbox'] = $notification['inbox']; - } - if (isset($notification['big_pic_path']) && is_string($notification['big_pic_path'])) { - $android['big_pic_path'] = $notification['big_pic_path']; - } - } - $this->androidNotification = $android; - - return $this; - } - - /** - * 自定义消息体设置 - * @param $msgContent - * @param array $msg - * @author zhaoxiang - * @return $this - */ - public function message($msgContent, array $msg = array()) { - if (is_string($msgContent)) { - $message = array(); - $message['msg_content'] = $msgContent; - if (!empty($msg)) { - if (isset($msg['title']) && is_string($msg['title'])) { - $message['title'] = $msg['title']; - } - if (isset($msg['content_type']) && is_string($msg['content_type'])) { - $message['content_type'] = $msg['content_type']; - } - if (isset($msg['extras']) && is_array($msg['extras']) && !empty($msg['extras'])) { - $message['extras'] = $msg['extras']; - } - } - $this->message = $message; - } - - return $this; - } - - /** - * 额外可选配置参数 - * @param array $opts - * @author zhaoxiang - * @return $this - */ - public function options(array $opts = array()) { - $options = array(); - if (isset($opts['sendno']) && is_int($opts['sendno'])) { - $options['sendno'] = $opts['sendno']; - } - if (isset($opts['time_to_live']) && is_int($opts['time_to_live']) && $opts['time_to_live'] <= 864000 && $opts['time_to_live'] >= 0) { - $options['time_to_live'] = $opts['time_to_live']; - } - if (isset($opts['override_msg_id']) && is_long($opts['override_msg_id'])) { - $options['override_msg_id'] = $opts['override_msg_id']; - } - if (isset($opts['apns_production']) && is_bool($opts['apns_production'])) { - $options['apns_production'] = $opts['apns_production']; - } else { - $options['apns_production'] = false; - } - if (isset($opts['big_push_duration']) && is_int($opts['big_push_duration']) && $opts['big_push_duration'] <= 1400 && $opts['big_push_duration'] >= 0) { - $options['big_push_duration'] = $opts['big_push_duration']; - } - $this->options = $options; - - return $this; - } - - /** - * 根据配置,整合数据 - * @author zhaoxiang - * @return array - */ - private function buildData() { - $payload = array(); - $payload["platform"] = $this->platform; - - $audience = array(); - if (!is_null($this->tag)) { - $audience["tag"] = $this->tag; - } - if (!is_null($this->tagAnd)) { - $audience["tag_and"] = $this->tagAnd; - } - if (!is_null($this->alias)) { - $audience["alias"] = $this->alias; - } - if (!is_null($this->registrationId)) { - $audience["registration_id"] = $this->registrationId; - } - if (count($audience) <= 0) { - $payload["audience"] = 'all'; - } else { - $payload["audience"] = $audience; - } - - $notification = array(); - if (!is_null($this->notificationAlert)) { - $notification['alert'] = $this->notificationAlert; - } - if (!is_null($this->androidNotification)) { - $notification['android'] = $this->androidNotification; - if (is_null($this->androidNotification['alert'])) { - if (is_null($this->notificationAlert)) { - Response::error(ReturnCode::EXCEPTION, 'Android alert can not be null'); - } - } else { - $notification['android']['alert'] = $this->androidNotification['alert']; - } - } - if (!is_null($this->extras)) { - $notification['android']['extras'] = $this->extras; - } - - - if (!is_null($this->iosNotification)) { - $notification['ios'] = $this->iosNotification; - if (is_null($this->iosNotification['alert'])) { - if (is_null($this->notificationAlert)) { - Response::error(ReturnCode::EXCEPTION, 'iOS alert can not be null'); - } - } else { - $notification['ios']['alert'] = $this->iosNotification['alert']; - } - } - if (!is_null($this->extras)) { - $notification['ios']['extras'] = $this->extras; - } - - if (count($notification) > 0) { - $payload['notification'] = $notification; - } - if (count($this->message) > 0) { - $payload['message'] = $this->message; - } - if (!array_key_exists('notification', $payload) && !array_key_exists('message', $payload)) { - Response::error(ReturnCode::EXCEPTION, 'notification and message can not all be null'); - } - if (!is_null($this->options)) { - $payload['options'] = $this->options; - } - - return $payload; - } - - public function send() { - return Http::post(Config::API_PUSH, $this->buildData()); - } -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Report.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Report.class.php deleted file mode 100644 index a7175a8..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Report.class.php +++ /dev/null @@ -1,13 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -class Report { - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPush/Schedule.class.php b/Application/Home/ApiStore/ApiSDK/JPush/Schedule.class.php deleted file mode 100644 index 6c38b7c..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPush/Schedule.class.php +++ /dev/null @@ -1,13 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\JPush; - - -class Schedule { - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/JPushSDK.class.php b/Application/Home/ApiStore/ApiSDK/JPushSDK.class.php deleted file mode 100644 index 331e431..0000000 --- a/Application/Home/ApiStore/ApiSDK/JPushSDK.class.php +++ /dev/null @@ -1,33 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK; - - -use Home\ApiStore\ApiSDK\JPush\Device; -use Home\ApiStore\ApiSDK\JPush\Push; -use Home\ApiStore\ApiSDK\JPush\Report; -use Home\ApiStore\ApiSDK\JPush\Schedule; - -class JPushSDK { - - public static function push() { - return new Push(); - } - - public static function report() { - return new Report(); - } - - public static function device() { - return new Device(); - } - - public static function schedule() { - return new Schedule(); - } -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/TaoBao/AuthSign.class.php b/Application/Home/ApiStore/ApiSDK/TaoBao/AuthSign.class.php deleted file mode 100644 index 6360925..0000000 --- a/Application/Home/ApiStore/ApiSDK/TaoBao/AuthSign.class.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -class AuthSign { - - /** - * 获取身份秘钥 - * @param array $params - * @param array $appInfo - * @author zhaoxiang - * @return string - */ - public static function getSign($params, $appInfo) { - ksort($params); - - $stringToBeSigned = $appInfo['secretKey']; - foreach ($params as $k => $v) { - if (is_string($v) && "@" != substr($v, 0, 1)) { - $stringToBeSigned .= "$k$v"; - } - } - $stringToBeSigned .= $appInfo['secretKey']; - - return strtoupper(md5($stringToBeSigned)); - } - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/TaoBao/Http.class.php b/Application/Home/ApiStore/ApiSDK/TaoBao/Http.class.php deleted file mode 100644 index 81b6c17..0000000 --- a/Application/Home/ApiStore/ApiSDK/TaoBao/Http.class.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK\TaoBao; - - -use Home\ORG\Response; - -class Http { - - public static function get($url) { - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_FAILONERROR, false); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, "top-sdk-php"); - - if (strlen($url) > 5 && strtolower(substr($url, 0, 5)) == "https") { - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); - } - $response = curl_exec($ch); - - if (curl_errno($ch)) { - Response::error(curl_error($ch)); - } else { - Response::error($response); - } - curl_close($ch); - - return $response; - } - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/ApiSDK/TaoBaoSDK.class.php b/Application/Home/ApiStore/ApiSDK/TaoBaoSDK.class.php deleted file mode 100644 index 1cda8f7..0000000 --- a/Application/Home/ApiStore/ApiSDK/TaoBaoSDK.class.php +++ /dev/null @@ -1,70 +0,0 @@ - - */ - -namespace Home\ApiStore\ApiSDK; - - -use Home\ApiStore\ApiSDK\TaoBao\AuthSign; - -class TaoBaoSDK { - - private $appInfo; //接口URL、AppID、AppSecret - private $method; //接口名称 - private $session; - - private $format = 'json'; - private $signMethod = 'md5'; - private $version = '2.0'; - - private $sysParams; - private $apiParams; - - public $url; - - /** - * TaoBaoSDK constructor. - * @param array $appInfo 应用信息 - * @param string $method 接口名称 - * @param string $session - */ - public function __construct($appInfo, $method, $session = null) { - $this->appInfo = $appInfo; - $this->method = $method; - $this->session = $session; - } - - public function buildSysParams() { - $this->sysParams["app_key"] = $this->appInfo['appKey']; - $this->sysParams["v"] = $this->version; - $this->sysParams["format"] = $this->format; - $this->sysParams["sign_method"] = $this->signMethod; - $this->sysParams["method"] = $this->method; - $this->sysParams["timestamp"] = date("Y-m-d H:i:s"); - - if (!is_null($this->session)) { - $this->sysParams["session"] = $this->session; - } - - return $this; - } - - public function buildApiParams($params, $rule) { - $together = array_intersect_key($params, $rule); - $this->apiParams = array_merge($rule, $together); - - return $this; - } - - public function buildUrl() { - $allParams = array_merge($this->sysParams, $this->apiParams); - $allParams['sign'] = AuthSign::getSign($allParams, $this->appInfo); - $this->url = $this->appInfo['url'].'?'.http_build_query($allParams); - - return $this; - } - -} \ No newline at end of file diff --git a/Application/Home/ApiStore/DayuSms.class.php b/Application/Home/ApiStore/DayuSms.class.php deleted file mode 100644 index 2307cb7..0000000 --- a/Application/Home/ApiStore/DayuSms.class.php +++ /dev/null @@ -1,39 +0,0 @@ - - */ - -namespace Home\ApiStore; - - -use Home\ApiStore\ApiSDK\TaoBao\Http; -use Home\ApiStore\ApiSDK\TaoBaoSDK; - -class DayuSms { - - private $appInfo = array( - 'secretKey' => '880ad9f6daae467f2ec2e11f50932f8f', - 'appKey' => '23762660', - 'url' => 'http://gw.api.taobao.com/router/rest' - ); - - private $apiRule = array( - 'sms_type' => 'normal', - 'sms_free_sign_name' => '', - 'rec_num' => '', - 'sms_template_code' => '' - ); - - public function send(){ - $sdk = new TaoBaoSDK($this->appInfo, 'alibaba.aliqin.fc.sms.num.send'); - $sdk->buildSysParams(); - $sdk->buildApiParams(array( - 'sms_free_sign_name' => 'Api管理后台', - 'rec_num' => '17366005512', - 'sms_template_code' => 'SMS_62650093' - ), $this->apiRule); - $sdk->buildUrl(); - return Http::get($sdk->url); - } -} \ No newline at end of file