mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 变更自带三方SDK,默认支持ApiAdmin的互联
This commit is contained in:
parent
f9e98a8363
commit
e46d347a0d
78
Application/Home/ApiStore/ApiAdminSDK.class.php
Normal file
78
Application/Home/ApiStore/ApiAdminSDK.class.php
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2017/05/10 创建
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
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 <zhaoxiang051405@gmail.com>
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function buildUrl($data = array()) {
|
||||||
|
if ($data) {
|
||||||
|
$queryStr = '?';
|
||||||
|
$queryStr .= http_build_query($data);
|
||||||
|
} else {
|
||||||
|
$queryStr = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->baseUrl . $this->method . $queryStr;
|
||||||
|
}
|
||||||
|
}
|
62
Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php
Normal file
62
Application/Home/ApiStore/ApiSDK/ApiAdmin/AuthSign.class.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Home\ApiStore\ApiSDK\ApiAdmin;
|
||||||
|
/**
|
||||||
|
* 淘宝开放平台秘钥计算
|
||||||
|
* @since 2017/04/20 创建
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
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 <zhaoxiang051405@gmail.com>
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getSignature($data) {
|
||||||
|
ksort($data);
|
||||||
|
$preStr = http_build_query($data);
|
||||||
|
|
||||||
|
return md5($preStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php
Normal file
77
Application/Home/ApiStore/ApiSDK/ApiAdmin/Http.class.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ApiAdmin通讯类
|
||||||
|
* @since 2017/04/20 创建
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,55 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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";
|
|
||||||
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Home\ApiStore\ApiSDK\JPush;
|
|
||||||
|
|
||||||
|
|
||||||
class Device {
|
|
||||||
|
|
||||||
}
|
|
@ -1,146 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,443 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* JPush推送实现
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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 <zhaoxiang051405@gmail.com>
|
|
||||||
* @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());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Home\ApiStore\ApiSDK\JPush;
|
|
||||||
|
|
||||||
|
|
||||||
class Report {
|
|
||||||
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Home\ApiStore\ApiSDK\JPush;
|
|
||||||
|
|
||||||
|
|
||||||
class Schedule {
|
|
||||||
|
|
||||||
}
|
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* 极光推送Manager
|
|
||||||
* @since 2017/03/24 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace Home\ApiStore\ApiSDK\TaoBao;
|
|
||||||
/**
|
|
||||||
* 淘宝开放平台秘钥计算
|
|
||||||
* @since 2017/04/20 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
class AuthSign {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取身份秘钥
|
|
||||||
* @param array $params
|
|
||||||
* @param array $appInfo
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
* @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));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* 淘宝API通讯类
|
|
||||||
* @since 2017/04/20 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @since 2017/04/20 创建
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* @since 2017-04-20
|
|
||||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user