[更新]统一修改二元运算符

This commit is contained in:
Anyon 2018-01-29 10:16:01 +08:00
parent 0c40df2a2f
commit c6eae22835
11 changed files with 43 additions and 42 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -14,7 +14,6 @@
namespace Wechat;
use Wechat\Contracts\Wechat;
/**

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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,

View File

@ -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]);
}
/**

View File

@ -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);