From c6eae22835b1796678184e03d4e1bc435dc1a5c9 Mon Sep 17 00:00:00 2001 From: Anyon Date: Mon, 29 Jan 2018 10:16:01 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E7=BB=9F=E4=B8=80=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BA=8C=E5=85=83=E8=BF=90=E7=AE=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wechat/Card.php | 20 ++++++++++---------- Wechat/Contracts/Tools.php | 4 ++-- Wechat/Custom.php | 2 +- Wechat/Oauth.php | 1 - Wechat/Product.php | 8 ++++---- Wechat/Qrcode.php | 2 +- Wechat/Receive.php | 2 +- Wechat/Scan.php | 6 +++--- Wechat/Script.php | 19 ++++++++++--------- Wechat/Shake.php | 10 +++++----- Wechat/Wifi.php | 11 ++++++----- 11 files changed, 43 insertions(+), 42 deletions(-) diff --git a/Wechat/Card.php b/Wechat/Card.php index 5088bfb..2c34a58 100644 --- a/Wechat/Card.php +++ b/Wechat/Card.php @@ -181,8 +181,8 @@ class Card extends Wechat public function getCode($code, $card_id = null, $check_consume = null) { $data = ['code' => $code]; - is_null($card_id) ?: $data['card_id'] = $card_id; - is_null($check_consume) ?: $data['check_consume'] = $check_consume; + is_null($card_id) || $data['card_id'] = $card_id; + is_null($check_consume) || $data['check_consume'] = $check_consume; $url = "https://api.weixin.qq.com/card/code/get?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -199,7 +199,7 @@ class Card extends Wechat public function consume($code, $card_id = null) { $data = ['code' => $code]; - is_null($card_id) ?: $data['card_id'] = $card_id; + is_null($card_id) || $data['card_id'] = $card_id; $url = "https://api.weixin.qq.com/card/code/consume?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -230,7 +230,7 @@ class Card extends Wechat public function getCardList($openid, $card_id = null) { $data = ['openid' => $openid]; - is_null($card_id) ?: $data['card_id'] = $card_id; + is_null($card_id) || $data['card_id'] = $card_id; $url = "https://api.weixin.qq.com/card/user/getcardlist?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -262,7 +262,7 @@ class Card extends Wechat public function batchGet($offset, $count = 50, array $status_list = []) { $data = ['offset' => $offset, 'count' => $count]; - empty($status_list) ?: $data['status_list'] = $status_list; + empty($status_list) || $data['status_list'] = $status_list; $url = "https://api.weixin.qq.com/card/batchget?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -295,8 +295,8 @@ class Card extends Wechat public function modifyStock($card_id, $increase_stock_value = null, $reduce_stock_value = null) { $data = ['card_id' => $card_id]; - is_null($increase_stock_value) ?: $data['increase_stock_value'] = $increase_stock_value; - is_null($reduce_stock_value) ?: $data['reduce_stock_value'] = $reduce_stock_value; + is_null($increase_stock_value) || $data['increase_stock_value'] = $increase_stock_value; + is_null($reduce_stock_value) || $data['reduce_stock_value'] = $reduce_stock_value; $url = "https://api.weixin.qq.com/card/modifystock?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -314,7 +314,7 @@ class Card extends Wechat public function updateCode($code, $new_code, $card_id = null) { $data = ['code' => $code, 'new_code' => $new_code]; - is_null($card_id) ?: $data['card_id'] = $card_id; + is_null($card_id) || $data['card_id'] = $card_id; $url = "https://api.weixin.qq.com/card/code/update?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -346,7 +346,7 @@ class Card extends Wechat public function unAvailable($code, $card_id, $reason = null) { $data = ['code' => $code, 'card_id' => $card_id]; - is_null($reason) ?: $data['reason'] = $reason; + is_null($reason) || $data['reason'] = $reason; $url = "https://api.weixin.qq.com/card/code/unavailable?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -382,7 +382,7 @@ class Card extends Wechat public function getCardCardinfo($begin_date, $end_date, $cond_source, $card_id = null) { $data = ['begin_date' => $begin_date, 'end_date' => $end_date, 'cond_source' => $cond_source]; - is_null($card_id) ?: $data['card_id'] = $card_id; + is_null($card_id) || $data['card_id'] = $card_id; $url = "https://api.weixin.qq.com/datacube/getcardcardinfo?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); diff --git a/Wechat/Contracts/Tools.php b/Wechat/Contracts/Tools.php index 07e297f..6b52791 100644 --- a/Wechat/Contracts/Tools.php +++ b/Wechat/Contracts/Tools.php @@ -113,8 +113,8 @@ class Tools */ public static function createCurlFile($filename, $mimetype = '', $postname = '') { - $basename = $postname ?: basename($filename); - $basemine = $mimetype ?: self::getExtMine(pathinfo($filename, 4)); + $basename = $postname || basename($filename); + $basemine = $mimetype || self::getExtMine(pathinfo($filename, 4)); if (function_exists('curl_file_create')) { return curl_file_create($filename, $basemine, $basename); } diff --git a/Wechat/Custom.php b/Wechat/Custom.php index 763599a..dfbf77e 100644 --- a/Wechat/Custom.php +++ b/Wechat/Custom.php @@ -155,7 +155,7 @@ class Custom extends Wechat public function massDelete($msg_id, $article_idx = null) { $data = ['msg_id' => $msg_id]; - is_null($article_idx) ?: $article_idx; + is_null($article_idx) || $article_idx; $url = "https://api.weixin.qq.com/cgi-bin/message/mass/delete?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); diff --git a/Wechat/Oauth.php b/Wechat/Oauth.php index da2f767..0a5aefb 100644 --- a/Wechat/Oauth.php +++ b/Wechat/Oauth.php @@ -14,7 +14,6 @@ namespace Wechat; - use Wechat\Contracts\Wechat; /** diff --git a/Wechat/Product.php b/Wechat/Product.php index f868cba..df88536 100644 --- a/Wechat/Product.php +++ b/Wechat/Product.php @@ -70,7 +70,7 @@ class Product extends Wechat public function getQrcode($keystandard, $keystr, $qrcode_size, $extinfo = []) { $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size]; - empty($extinfo) ?: $data['extinfo'] = $extinfo; + empty($extinfo) || $data['extinfo'] = $extinfo; $url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -87,7 +87,7 @@ class Product extends Wechat public function getProduct($keystandard, $keystr) { $data = ['keystandard' => $keystandard, 'keystr' => $keystr]; - empty($extinfo) ?: $data['extinfo'] = $extinfo; + empty($extinfo) || $data['extinfo'] = $extinfo; $url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -106,8 +106,8 @@ class Product extends Wechat public function getProductList($offset, $limit = 10, $status = null, $keystr = '') { $data = ['offset' => $offset, 'limit' => $limit]; - is_null($status) ?: $data['status'] = $status; - empty($keystr) ?: $data['keystr'] = $keystr; + is_null($status) || $data['status'] = $status; + empty($keystr) || $data['keystr'] = $keystr; $url = "https://api.weixin.qq.com/scan/product/get?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); diff --git a/Wechat/Qrcode.php b/Wechat/Qrcode.php index 4bd9c4f..625acf1 100644 --- a/Wechat/Qrcode.php +++ b/Wechat/Qrcode.php @@ -39,7 +39,7 @@ class Qrcode extends Wechat } else { $data = ['action_name' => 'QR_LIMIT_STR_SCENE', 'action_info' => ['scene' => ['scene_str' => $scene]]]; } - empty($expire_seconds) ?: $data['expire_seconds'] = $expire_seconds; + empty($expire_seconds) || $data['expire_seconds'] = $expire_seconds; $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); diff --git a/Wechat/Receive.php b/Wechat/Receive.php index 077dc63..44ca865 100644 --- a/Wechat/Receive.php +++ b/Wechat/Receive.php @@ -37,7 +37,7 @@ class Receive extends Request 'FromUserName' => $this->getToOpenid(), 'MsgType' => 'transfer_customer_service', ]; - empty($account) ?: $this->message['TransInfo'] = ['KfAccount' => $account]; + empty($account) || $this->message['TransInfo'] = ['KfAccount' => $account]; return $this; } diff --git a/Wechat/Scan.php b/Wechat/Scan.php index 9ec9a5e..21a23fe 100644 --- a/Wechat/Scan.php +++ b/Wechat/Scan.php @@ -96,7 +96,7 @@ class Scan extends Wechat public function getQrc($keystandard, $keystr, $extinfo = null, $qrcode_size = 64) { $data = ['keystandard' => $keystandard, 'keystr' => $keystr, 'qrcode_size' => $qrcode_size]; - is_null($extinfo) ?: $data['extinfo'] = $extinfo; + is_null($extinfo) || $data['extinfo'] = $extinfo; $url = "https://api.weixin.qq.com/scan/product/getqrcode?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -130,8 +130,8 @@ class Scan extends Wechat public function getProductList($offset = 1, $limit = 10, $status = null, $keystr = null) { $data = ['offset' => $offset, 'limit' => $limit]; - is_null($status) ?: $data['status'] = $status; - is_null($keystr) ?: $data['keystr'] = $keystr; + is_null($status) || $data['status'] = $status; + is_null($keystr) || $data['keystr'] = $keystr; $url = "https://api.weixin.qq.com/scan/product/getlist?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); diff --git a/Wechat/Script.php b/Wechat/Script.php index 0a237b1..875464b 100644 --- a/Wechat/Script.php +++ b/Wechat/Script.php @@ -32,9 +32,9 @@ class Script extends Wechat * @param string $appid 强制指定有效APPID * @return void */ - public function delTicket($type = 'jsapi', $appid = '') + public function delTicket($type = 'jsapi', $appid = null) { - empty($appid) ?: $appid = $this->config->get('appid'); + is_null($appid) && $appid = $this->config->get('appid'); $cache_name = "wechat_{$type}_ticket_{$appid}"; Tools::delCache($cache_name); } @@ -47,9 +47,9 @@ class Script extends Wechat * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ - public function getTicket($type = 'jsapi', $appid = '') + public function getTicket($type = 'jsapi', $appid = null) { - empty($appid) ?: $appid = $this->config->get('appid'); + is_null($appid) && $appid = $this->config->get('appid'); $cache_name = "wechat_{$type}_ticket_{$appid}"; $ticket = Tools::getCache($cache_name); if (empty($ticket)) { @@ -59,7 +59,8 @@ class Script extends Wechat if (empty($result['ticket'])) { throw new InvalidResponseException('Invalid Resoponse Ticket.', '0'); } - Tools::setCache($cache_name, $ticket = $result['ticket']); + $ticket = $result['ticket']; + Tools::setCache($cache_name, $ticket, 5000); } return $ticket; } @@ -73,12 +74,12 @@ class Script extends Wechat * @throws Exceptions\LocalCacheException * @throws InvalidResponseException */ - public function getJsSign($url, $appid = '', $ticket = '') + public function getJsSign($url, $appid = null, $ticket = null) { list($url,) = explode('#', $url); - empty($ticket) ?: $ticket = $this->getTicket('jsapi'); - empty($appid) ?: $appid = $this->config->get('appid'); - $data = ["url" => $url, "timestamp" => time(), "jsapi_ticket" => $ticket, "noncestr" => Tools::createNoncestr(16)]; + is_null($ticket) && $ticket = $this->getTicket('jsapi'); + is_null($appid) && $appid = $this->config->get('appid'); + $data = ["url" => $url, "timestamp" => '' . time(), "jsapi_ticket" => $ticket, "noncestr" => Tools::createNoncestr(16)]; return [ 'debug' => false, "appId" => $appid, diff --git a/Wechat/Shake.php b/Wechat/Shake.php index bcea93d..5f34791 100644 --- a/Wechat/Shake.php +++ b/Wechat/Shake.php @@ -65,8 +65,8 @@ class Shake extends Wechat public function createApply($quantity, $apply_reason, $comment = null, $poi_id = null) { $data = ['quantity' => $quantity, 'apply_reason' => $apply_reason]; - is_null($poi_id) ?: $data['poi_id'] = $poi_id; - is_null($comment) ?: $data['comment'] = $comment; + is_null($poi_id) || $data['poi_id'] = $poi_id; + is_null($comment) || $data['comment'] = $comment; $url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -74,16 +74,16 @@ class Shake extends Wechat /** * 查询设备ID申请审核状态 - * @param integer $apply_id 批次ID,申请设备ID时所返回的批次ID + * @param integer $applyId 批次ID,申请设备ID时所返回的批次ID * @return array * @throws Exceptions\InvalidResponseException * @throws Exceptions\LocalCacheException */ - public function getApplyStatus($apply_id) + public function getApplyStatus($applyId) { $url = "https://api.weixin.qq.com/shakearound/device/applyid?access_token=ACCESS_TOKEN"; $this->registerApi($url, __FUNCTION__, func_get_args()); - return $this->httpPostForJson($url, ['apply_id' => $apply_id]); + return $this->httpPostForJson($url, ['apply_id' => $applyId]); } /** diff --git a/Wechat/Wifi.php b/Wechat/Wifi.php index a60afeb..4b23ed5 100644 --- a/Wechat/Wifi.php +++ b/Wechat/Wifi.php @@ -24,6 +24,7 @@ use Wechat\Contracts\Wechat; */ class Wifi extends Wechat { + /** * 获取 Wi-Fi 门店列表 * @param integer $pageindex 分页下标,默认从1开始 @@ -66,7 +67,7 @@ class Wifi extends Wechat public function upShopWifi($shop_id, $old_ssid, $ssid, $password = null) { $data = ['shop_id' => $shop_id, 'old_ssid' => $old_ssid, 'ssid' => $ssid]; - is_null($password) ?: $data['password'] = $password; + is_null($password) || $data['password'] = $password; $url = 'https://api.weixin.qq.com/bizwifi/shop/update?access_token=ACCESS_TOKEN'; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -132,9 +133,9 @@ class Wifi extends Wechat public function queryShopWifi($shop_id = null, $pageindex = null, $pagesize = null) { $data = []; - is_null($pagesize) ?: $data['pagesize'] = $pagesize; - is_null($pageindex) ?: $data['pageindex'] = $pageindex; - is_null($shop_id) ?: $data['shop_id'] = $shop_id; + is_null($pagesize) || $data['pagesize'] = $pagesize; + is_null($pageindex) || $data['pageindex'] = $pageindex; + is_null($shop_id) || $data['shop_id'] = $shop_id; $url = 'https://api.weixin.qq.com/bizwifi/device/list?access_token=ACCESS_TOKEN'; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data); @@ -182,7 +183,7 @@ class Wifi extends Wechat public function setHomePage($shop_id, $template_id, $url = null) { $data = ['shop_id' => $shop_id, 'template_id' => $template_id]; - is_null($url) ?: $data['struct'] = ['url' => $url]; + is_null($url) && $data['struct'] = ['url' => $url]; $url = 'https://api.weixin.qq.com/bizwifi/homepage/set?access_token=ACCESS_TOKEN'; $this->registerApi($url, __FUNCTION__, func_get_args()); return $this->httpPostForJson($url, $data);