From c0c55fe440418267ae97cc45809e4064c95744d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 18 Jul 2017 20:00:27 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=9B=B4=E6=96=B0]=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96,=20=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0getCo?= =?UTF-8?q?nfig=E4=B8=8EgetAppid=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wechat/Lib/Cache.php | 24 +++--- Wechat/Lib/Common.php | 44 ++++++++--- Wechat/Lib/Prpcrypt.php | 30 +++++--- Wechat/Lib/Tools.php | 80 ++++++++++++-------- Wechat/Loader.php | 19 +++-- Wechat/WechatCard.php | 90 +++++++++++++++-------- Wechat/WechatCustom.php | 39 ++++++---- Wechat/WechatDevice.php | 48 ++++++++---- Wechat/WechatExtends.php | 18 +++-- Wechat/WechatHardware.php | 21 ++++-- Wechat/WechatMedia.php | 48 +++++++----- Wechat/WechatMenu.php | 21 ++++-- Wechat/WechatOauth.php | 18 +++-- Wechat/WechatPay.php | 75 ++++++++++++------- Wechat/WechatPoi.php | 21 ++++-- Wechat/WechatReceive.php | 149 +++++++++++++++++++++++++------------- Wechat/WechatScript.php | 12 ++- Wechat/WechatService.php | 53 +++++++++----- Wechat/WechatUser.php | 69 ++++++++++++------ test.php | 2 +- 20 files changed, 584 insertions(+), 297 deletions(-) diff --git a/Wechat/Lib/Cache.php b/Wechat/Lib/Cache.php index 0335f6f..1bf066e 100644 --- a/Wechat/Lib/Cache.php +++ b/Wechat/Lib/Cache.php @@ -10,7 +10,8 @@ * @author Anyon * @date 2016-08-20 17:50 */ -class Cache { +class Cache +{ /** * 缓存位置 @@ -25,7 +26,8 @@ class Cache { * @param int $expired * @return mixed */ - static public function set($name, $value, $expired = 0) { + static public function set($name, $value, $expired = 0) + { if (isset(Loader::$callback['CacheSet'])) { return call_user_func_array(Loader::$callback['CacheSet'], func_get_args()); } @@ -38,7 +40,8 @@ static public function set($name, $value, $expired = 0) { * @param string $name * @return mixed */ - static public function get($name) { + static public function get($name) + { if (isset(Loader::$callback['CacheGet'])) { return call_user_func_array(Loader::$callback['CacheGet'], func_get_args()); } @@ -56,7 +59,8 @@ static public function get($name) { * @param string $name * @return mixed */ - static public function del($name) { + static public function del($name) + { if (isset(Loader::$callback['CacheDel'])) { return call_user_func_array(Loader::$callback['CacheDel'], func_get_args()); } @@ -69,7 +73,8 @@ static public function del($name) { * @param string $filename * @return mixed */ - static public function put($line, $filename = '') { + static public function put($line, $filename = '') + { if (isset(Loader::$callback['CachePut'])) { return call_user_func_array(Loader::$callback['CachePut'], func_get_args()); } @@ -81,13 +86,14 @@ static public function put($line, $filename = '') { * 检查缓存目录 * @return bool */ - static protected function check() { + static protected function check() + { empty(self::$cachepath) && self::$cachepath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR; self::$cachepath = rtrim(self::$cachepath, '/\\') . DIRECTORY_SEPARATOR; - if (!is_dir(self::$cachepath) && !mkdir(self::$cachepath, 0755, TRUE)) { - return FALSE; + if (!is_dir(self::$cachepath) && !mkdir(self::$cachepath, 0755, true)) { + return false; } - return TRUE; + return true; } } diff --git a/Wechat/Lib/Common.php b/Wechat/Lib/Common.php index d0af0d6..7a0c907 100644 --- a/Wechat/Lib/Common.php +++ b/Wechat/Lib/Common.php @@ -13,7 +13,8 @@ * @author Anyon * @date 2016/05/28 11:55 */ -class Common { +class Common +{ /** API接口URL需要使用此前缀 */ const API_BASE_URL_PREFIX = 'https://api.weixin.qq.com'; @@ -31,13 +32,14 @@ class Common { public $errCode = 0; public $errMsg = ""; public $config = array(); - private $_retry = FALSE; + private $_retry = false; /** * 构造方法 * @param array $options */ - public function __construct($options = array()) { + public function __construct($options = array()) + { $config = Loader::config($options); $this->token = isset($config['token']) ? $config['token'] : ''; $this->appid = isset($config['appid']) ? $config['appid'] : ''; @@ -46,11 +48,31 @@ public function __construct($options = array()) { $this->config = $config; } + /** + * 获取当前操作公众号APPID + * @return string + */ + public function getAppid() + { + return $this->appid; + } + + /** + * 获取SDK配置参数 + * @return array + */ + public function getConfig() + { + return $this->config; + } + + /** * 接口验证 * @return bool */ - public function valid() { + public function valid() + { $encryptStr = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { $postStr = file_get_contents("php://input"); @@ -58,7 +80,7 @@ public function valid() { $this->encrypt_type = isset($_GET["encrypt_type"]) ? $_GET["encrypt_type"] : ''; if ($this->encrypt_type == 'aes') { $encryptStr = $array['Encrypt']; - !class_exists('Prpcrypt', FALSE) && require __DIR__ . '/Prpcrypt.php'; + !class_exists('Prpcrypt', false) && require __DIR__ . '/Prpcrypt.php'; $pc = new Prpcrypt($this->encodingAesKey); $array = $pc->decrypt($encryptStr, $this->appid); if (!isset($array[0]) || intval($array[0]) > 0) { @@ -91,7 +113,8 @@ public function valid() { * @param string $str * @return bool */ - private function checkSignature($str = '') { + private function checkSignature($str = '') + { // 如果存在加密验证则用加密验证段 $signature = isset($_GET["msg_signature"]) ? $_GET["msg_signature"] : (isset($_GET["signature"]) ? $_GET["signature"] : ''); $timestamp = isset($_GET["timestamp"]) ? $_GET["timestamp"] : ''; @@ -112,7 +135,8 @@ private function checkSignature($str = '') { * @param string $token 手动指定access_token,非必要情况不建议用 * @return bool|string */ - public function getAccessToken($appid = '', $appsecret = '', $token = '') { + public function getAccessToken($appid = '', $appsecret = '', $token = '') + { if (!$appid || !$appsecret) { $appid = $this->appid; $appsecret = $this->appsecret; @@ -151,7 +175,8 @@ public function getAccessToken($appid = '', $appsecret = '', $token = '') { * @param array $arguments SDK方法参数 * @return bool|mixed */ - protected function checkRetry($method, $arguments = array()) { + protected function checkRetry($method, $arguments = array()) + { if (!$this->_retry && in_array($this->errCode, array('40014', '40001', '41001', '42001'))) { Tools::log("Run {$method} Faild. {$this->errMsg}[{$this->errCode}]", 'ERR'); ($this->_retry = true) && $this->resetAuth(); @@ -168,7 +193,8 @@ protected function checkRetry($method, $arguments = array()) { * @param string $appid 如在类初始化时已提供,则可为空 * @return bool */ - public function resetAuth($appid = '') { + public function resetAuth($appid = '') + { $authname = 'wechat_access_token_' . (empty($appid) ? $this->appid : $appid); Tools::log("Reset Auth And Remove Old AccessToken."); $this->access_token = ''; diff --git a/Wechat/Lib/Prpcrypt.php b/Wechat/Lib/Prpcrypt.php index 0740462..caab56a 100644 --- a/Wechat/Lib/Prpcrypt.php +++ b/Wechat/Lib/Prpcrypt.php @@ -6,7 +6,8 @@ * @subpackage library * @date 2016/06/28 11:59 */ -class PKCS7Encoder { +class PKCS7Encoder +{ public static $block_size = 32; @@ -15,7 +16,8 @@ class PKCS7Encoder { * @param string $text 需要进行填充补位操作的明文 * @return string 补齐明文字符串 */ - function encode($text) { + function encode($text) + { $amount_to_pad = PKCS7Encoder::$block_size - (strlen($text) % PKCS7Encoder::$block_size); if ($amount_to_pad == 0) { $amount_to_pad = PKCS7Encoder::$block_size; @@ -33,7 +35,8 @@ function encode($text) { * @param string $text 解密后的明文 * @return string 删除填充补位后的明文 */ - function decode($text) { + function decode($text) + { $pad = ord(substr($text, -1)); if ($pad < 1 || $pad > PKCS7Encoder::$block_size) { $pad = 0; @@ -49,11 +52,13 @@ function decode($text) { * @subpackage library * @date 2016/06/28 11:59 */ -class Prpcrypt { +class Prpcrypt +{ public $key; - function __construct($k) { + function __construct($k) + { $this->key = base64_decode($k . "="); } @@ -63,7 +68,8 @@ function __construct($k) { * @param string $appid 公众号APPID * @return string 加密后的密文 */ - public function encrypt($text, $appid) { + public function encrypt($text, $appid) + { try { //获得16位随机字符串,填充到明文之前 $random = $this->getRandomStr();//"aaaabbbbccccdddd"; @@ -84,7 +90,8 @@ public function encrypt($text, $appid) { * @param string $appid 公众号APPID * @return string 解密得到的明文 */ - public function decrypt($encrypted, $appid) { + public function decrypt($encrypted, $appid) + { try { $iv = substr($this->key, 0, 16); $decrypted = openssl_decrypt($encrypted, 'AES-256-CBC', substr($this->key, 0, 32), OPENSSL_ZERO_PADDING, $iv); @@ -115,7 +122,8 @@ public function decrypt($encrypted, $appid) { * 随机生成16位字符串 * @return string 生成的字符串 */ - function getRandomStr() { + function getRandomStr() + { $str = ""; $str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($str_pol) - 1; @@ -132,7 +140,8 @@ function getRandomStr() { * 不用于官方API接口的errCode码 * Class ErrorCode */ -class ErrorCode { +class ErrorCode +{ public static $OK = 0; public static $ValidateSignatureError = 40001; @@ -166,7 +175,8 @@ class ErrorCode { * @param string $err * @return bool */ - public static function getErrText($err) { + public static function getErrText($err) + { if (isset(self::$errCode[$err])) { return self::$errCode[$err]; } diff --git a/Wechat/Lib/Tools.php b/Wechat/Lib/Tools.php index 691218e..974dcc2 100644 --- a/Wechat/Lib/Tools.php +++ b/Wechat/Lib/Tools.php @@ -12,7 +12,8 @@ * @author Anyon * @date 2016/05/28 11:55 */ -class Tools { +class Tools +{ /** * 产生随机字符串 @@ -20,7 +21,8 @@ class Tools { * @param string $str * @return string */ - static public function createNoncestr($length = 32, $str = "") { + static public function createNoncestr($length = 32, $str = "") + { $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; for ($i = 0; $i < $length; $i++) { $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); @@ -34,7 +36,8 @@ static public function createNoncestr($length = 32, $str = "") { * @param string $method 签名方法 * @return bool|string 签名值 */ - static public function getSignature($arrdata, $method = "sha1") { + static public function getSignature($arrdata, $method = "sha1") + { if (!function_exists($method)) { return false; } @@ -52,7 +55,8 @@ static public function getSignature($arrdata, $method = "sha1") { * @param string $partnerKey * @return string */ - static public function getPaySign($option, $partnerKey) { + static public function getPaySign($option, $partnerKey) + { ksort($option); $buff = ''; foreach ($option as $k => $v) { @@ -69,11 +73,13 @@ static public function getPaySign($option, $partnerKey) { * @param string $id 数字索引子节点key转换的属性名 * @return string */ - static public function arr2xml($data, $root = 'xml', $item = 'item', $id = 'id') { + static public function arr2xml($data, $root = 'xml', $item = 'item', $id = 'id') + { return "<{$root}>" . self::_data_to_xml($data, $item, $id) . ""; } - static private function _data_to_xml($data, $item = 'item', $id = 'id', $content = '') { + static private function _data_to_xml($data, $item = 'item', $id = 'id', $content = '') + { foreach ($data as $key => $val) { is_numeric($key) && $key = "{$item} {$id}=\"{$key}\""; $content .= "<{$key}>"; @@ -96,7 +102,8 @@ static private function _data_to_xml($data, $item = 'item', $id = 'id', $content * @param string $xml * @return array */ - static public function xml2arr($xml) { + static public function xml2arr($xml) + { return json_decode(Tools::json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); } @@ -105,7 +112,8 @@ static public function xml2arr($xml) { * @param array $array * @return string */ - static public function json_encode($array) { + static public function json_encode($array) + { return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', create_function('$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'), json_encode($array)); } @@ -114,11 +122,12 @@ static public function json_encode($array) { * @param $url * @return bool|mixed */ - static public function httpGet($url) { + static public function httpGet($url) + { $oCurl = curl_init(); - if (stripos($url, "https://") !== FALSE) { - curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE); + if (stripos($url, "https://") !== false) { + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); } curl_setopt($oCurl, CURLOPT_URL, $url); @@ -139,17 +148,18 @@ static public function httpGet($url) { * @param array|string $data * @return bool|mixed */ - static public function httpPost($url, $data) { + static public function httpPost($url, $data) + { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); - curl_setopt($ch, CURLOPT_HEADER, FALSE); - curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_POST, true); if (is_array($data)) { foreach ($data as &$value) { - if (is_string($value) && stripos($value, '@') === 0 && class_exists('CURLFile', FALSE)) { + if (is_string($value) && stripos($value, '@') === 0 && class_exists('CURLFile', false)) { $value = new CURLFile(realpath(trim($value, '@'))); } } @@ -172,15 +182,16 @@ static public function httpPost($url, $data) { * @param int $second 设置请求超时时间 * @return bool|mixed */ - static public function httpsPost($url, $postdata, $ssl_cer = null, $ssl_key = null, $second = 30) { + static public function httpsPost($url, $postdata, $ssl_cer = null, $ssl_key = null, $second = 30) + { $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, $second); curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); - curl_setopt($ch, CURLOPT_HEADER, FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_HEADER, false); /* 要求结果为字符串且输出到屏幕上 */ - curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); /* 设置证书 */ if (!is_null($ssl_cer) && file_exists($ssl_cer) && is_file($ssl_cer)) { curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM'); @@ -193,7 +204,7 @@ static public function httpsPost($url, $postdata, $ssl_cer = null, $ssl_key = nu curl_setopt($ch, CURLOPT_POST, true); if (is_array($postdata)) { foreach ($postdata as &$data) { - if (is_string($data) && stripos($data, '@') === 0 && class_exists('CURLFile', FALSE)) { + if (is_string($data) && stripos($data, '@') === 0 && class_exists('CURLFile', false)) { $data = new CURLFile(realpath(trim($data, '@'))); } } @@ -212,14 +223,15 @@ static public function httpsPost($url, $postdata, $ssl_cer = null, $ssl_key = nu * 读取微信客户端IP * @return null|string */ - static public function getAddress() { + static public function getAddress() + { foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP', 'REMOTE_ADDR') as $header) { - if (!isset($_SERVER[$header]) || ($spoof = $_SERVER[$header]) === NULL) { + if (!isset($_SERVER[$header]) || ($spoof = $_SERVER[$header]) === null) { continue; } sscanf($spoof, '%[^,]', $spoof); if (!filter_var($spoof, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { - $spoof = NULL; + $spoof = null; } else { return $spoof; } @@ -234,7 +246,8 @@ static public function getAddress() { * @param int $expired * @return bool */ - static public function setCache($cachename, $value, $expired = 0) { + static public function setCache($cachename, $value, $expired = 0) + { return Cache::set($cachename, $value, $expired); } @@ -243,7 +256,8 @@ static public function setCache($cachename, $value, $expired = 0) { * @param string $cachename * @return mixed */ - static public function getCache($cachename) { + static public function getCache($cachename) + { return Cache::get($cachename); } @@ -252,7 +266,8 @@ static public function getCache($cachename) { * @param string $cachename * @return bool */ - static public function removeCache($cachename) { + static public function removeCache($cachename) + { return Cache::del($cachename); } @@ -261,7 +276,8 @@ static public function removeCache($cachename) { * @param string $msg 日志行内容 * @param string $type 日志级别 */ - static public function log($msg, $type = 'MSG') { + static public function log($msg, $type = 'MSG') + { Cache::put($type . ' - ' . $msg); } diff --git a/Wechat/Loader.php b/Wechat/Loader.php index 370394a..346d25f 100644 --- a/Wechat/Loader.php +++ b/Wechat/Loader.php @@ -21,7 +21,8 @@ * @author Anyon * @date 2016-08-21 11:06 */ -class Loader { +class Loader +{ /** * 事件注册函数 @@ -47,8 +48,9 @@ class Loader { * @param string $method 处理方法(可以是普通方法或者类中的方法) * @param string|null $class 处理对象(可以直接使用的类实例) */ - static public function register($event, $method, $class = NULL) { - if (!empty($class) && class_exists($class, FALSE) && method_exists($class, $method)) { + static public function register($event, $method, $class = null) + { + if (!empty($class) && class_exists($class, false) && method_exists($class, $method)) { self::$callback[$event] = array($class, $method); } else { self::$callback[$event] = $method; @@ -61,7 +63,8 @@ static public function register($event, $method, $class = NULL) { * @param array $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img) * @return WechatCard|WechatCustom|WechatDevice|WechatExtends|WechatMedia|WechatMenu|WechatOauth|WechatPay|WechatPoi|WechatReceive|WechatScript|WechatService|WechatUser */ - static public function & get_instance($type, $config = array()) { + static public function & get_instance($type, $config = array()) + { return self::get($type, $config); } @@ -71,13 +74,14 @@ static public function & get_instance($type, $config = array()) { * @param array $config SDK配置(token,appid,appsecret,encodingaeskey,mch_id,partnerkey,ssl_cer,ssl_key,qrc_img) * @return WechatCard|WechatCustom|WechatDevice|WechatExtends|WechatMedia|WechatMenu|WechatOauth|WechatPay|WechatPoi|WechatReceive|WechatScript|WechatService|WechatUser */ - static public function & get($type, $config = array()) { + static public function & get($type, $config = array()) + { $index = md5(strtolower($type) . md5(json_encode(self::$config))); if (!isset(self::$cache[$index])) { $basicName = 'Wechat' . ucfirst(strtolower($type)); $className = "\\Wechat\\{$basicName}"; // 注册类的无命名空间别名,兼容未带命名空间的老版本SDK - !class_exists($basicName, FALSE) && class_alias($className, $basicName); + !class_exists($basicName, false) && class_alias($className, $basicName); self::$cache[$index] = new $className(self::config($config)); } return self::$cache[$index]; @@ -88,7 +92,8 @@ static public function & get($type, $config = array()) { * @param array $config * @return array */ - static public function config($config = array()) { + static public function config($config = array()) + { !empty($config) && self::$config = array_merge(self::$config, $config); if (!empty(self::$config['cachepath'])) { Cache::$cachepath = self::$config['cachepath']; diff --git a/Wechat/WechatCard.php b/Wechat/WechatCard.php index 5fb258f..c88d972 100644 --- a/Wechat/WechatCard.php +++ b/Wechat/WechatCard.php @@ -8,7 +8,8 @@ /** * 微信卡卷 */ -class WechatCard extends Common { +class WechatCard extends Common +{ /** 卡券相关地址 */ const CARD_CREATE = '/card/create?'; @@ -53,7 +54,8 @@ class WechatCard extends Common { * @param string $jsapi_ticket * @return bool|string */ - public function getJsCardTicket($appid = '', $jsapi_ticket = '') { + public function getJsCardTicket($appid = '', $jsapi_ticket = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -87,7 +89,8 @@ public function getJsCardTicket($appid = '', $jsapi_ticket = '') { * @param string $shopid 门店Id * @return array */ - public function createChooseCardJsPackage($cardid = NULL, $cardtype = NULL, $shopid = NULL) { + public function createChooseCardJsPackage($cardid = null, $cardtype = null, $shopid = null) + { $data = array(); $data['api_ticket'] = $this->getJsCardTicket(); $data['app_id'] = $this->appid; @@ -108,9 +111,11 @@ public function createChooseCardJsPackage($cardid = NULL, $cardtype = NULL, $sho * @param array $data 其它限定参数 * @return array */ - public function createAddCardJsPackage($cardid = NULL, $data = array()) { + public function createAddCardJsPackage($cardid = null, $data = array()) + { - function _sign($cardid = NULL, $attr = array(), $self) { + function _sign($cardid = null, $attr = array(), $self) + { unset($attr['outer_id']); $attr['cardId'] = $cardid; $attr['timestamp'] = time(); @@ -138,7 +143,8 @@ function _sign($cardid = NULL, $attr = array(), $self) { * @param string $method 签名方法 * @return bool|string 签名值 */ - public function getTicketSignature($arrdata, $method = "sha1") { + public function getTicketSignature($arrdata, $method = "sha1") + { if (!function_exists($method)) { return false; } @@ -155,7 +161,8 @@ public function getTicketSignature($arrdata, $method = "sha1") { * @param array $data 卡券数据 * @return bool|array 返回数组中card_id为卡券ID */ - public function createCard($data) { + public function createCard($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -178,7 +185,8 @@ public function createCard($data) { * @param string $data * @return bool */ - public function updateCard($data) { + public function updateCard($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -202,7 +210,8 @@ public function updateCard($data) { * @param string $card_id 卡券ID * @return bool */ - public function delCard($card_id) { + public function delCard($card_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -226,7 +235,8 @@ public function delCard($card_id) { * @param string $card_id 卡卷ID(可不给) * @return bool|array */ - public function getCardList($openid, $card_id = '') { + public function getCardList($openid, $card_id = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -250,7 +260,8 @@ public function getCardList($openid, $card_id = '') { * @param string $card_id 卡卷ID * @return bool|array */ - public function getCardMpHtml($card_id) { + public function getCardMpHtml($card_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -275,7 +286,8 @@ public function getCardMpHtml($card_id) { * @param array $code_list 卡卷code列表(一维数组) * @return bool|array */ - public function checkCardCodeList($card_id, $code_list) { + public function checkCardCodeList($card_id, $code_list) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -298,7 +310,8 @@ public function checkCardCodeList($card_id, $code_list) { * @param string $card_id 卡卷ID * @return bool|array */ - public function getCardInfo($card_id) { + public function getCardInfo($card_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -321,7 +334,8 @@ public function getCardInfo($card_id) { * 获得卡券的最新颜色列表,用于创建卡券 * @return bool|array */ - public function getCardColors() { + public function getCardColors() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -349,7 +363,8 @@ public function getCardColors() { * @param string $balance 红包余额,以分为单位。红包类型必填(LUCKY_MONEY),其他卡券类型不填。 * @return bool|string */ - public function createCardQrcode($card_id, $code = '', $openid = '', $expire_seconds = 0, $is_unique_code = false, $balance = '') { + public function createCardQrcode($card_id, $code = '', $openid = '', $expire_seconds = 0, $is_unique_code = false, $balance = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -387,7 +402,8 @@ public function createCardQrcode($card_id, $code = '', $openid = '', $expire_sec * "openid":"oFS7Fjl0WsZ9AMZqrI80nbIq8xrA" * } */ - public function consumeCardCode($code, $card_id = '') { + public function consumeCardCode($code, $card_id = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -416,7 +432,8 @@ public function consumeCardCode($code, $card_id = '') { * "code":"751234212312" * } */ - public function decryptCardCode($encrypt_code) { + public function decryptCardCode($encrypt_code) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -449,7 +466,8 @@ public function decryptCardCode($encrypt_code) { * } * } */ - public function checkCardCode($code) { + public function checkCardCode($code) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -479,7 +497,8 @@ public function checkCardCode($code) { * "total_num":1 //该商户名下 card_id 总数 * } */ - public function getCardIdList($offset = 0, $count = 50) { + public function getCardIdList($offset = 0, $count = 50) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -507,7 +526,8 @@ public function getCardIdList($offset = 0, $count = 50) { * @param string $new_code 新的卡券 code 编码 * @return bool */ - public function updateCardCode($code, $card_id, $new_code) { + public function updateCardCode($code, $card_id, $new_code) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -532,7 +552,8 @@ public function updateCardCode($code, $card_id, $new_code) { * @param string $card_id 自定义 code 的卡券必填。非自定义 code 的卡券不填。 * @return bool */ - public function unavailableCardCode($code, $card_id = '') { + public function unavailableCardCode($code, $card_id = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -556,7 +577,8 @@ public function unavailableCardCode($code, $card_id = '') { * @param string $data * @return bool */ - public function modifyCardStock($data) { + public function modifyCardStock($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -578,7 +600,8 @@ public function modifyCardStock($data) { * @param string $data * @return bool */ - public function updateMeetingCard($data) { + public function updateMeetingCard($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -600,7 +623,8 @@ public function updateMeetingCard($data) { * @param string $data 具体结构请参看卡券开发文档(6.1.1 激活/绑定会员卡)章节 * @return bool */ - public function activateMemberCard($data) { + public function activateMemberCard($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -623,7 +647,8 @@ public function activateMemberCard($data) { * @param string $data 具体结构请参看卡券开发文档(6.1.2 会员卡交易)章节 * @return bool|array */ - public function updateMemberCard($data) { + public function updateMemberCard($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -646,7 +671,8 @@ public function updateMemberCard($data) { * @param array $user 测试的微信号列表 * @return bool */ - public function setCardTestWhiteList($openid = array(), $user = array()) { + public function setCardTestWhiteList($openid = array(), $user = array()) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -673,7 +699,8 @@ public function setCardTestWhiteList($openid = array(), $user = array()) { * @param string $card_id 自定义 code 的卡券必填。非自定义 code 可不填。 * @return bool|array */ - public function updateLuckyMoney($code, $balance, $card_id = '') { + public function updateLuckyMoney($code, $balance, $card_id = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -701,7 +728,8 @@ public function updateLuckyMoney($code, $balance, $card_id = '') { * @param bool $need_remark_amount 用户核销时是否需要备注核销金额,填true/false,默认为false * @return bool|array */ - public function setSelfconsumecell($card_id, $is_openid = false, $need_verify_cod = false, $need_remark_amount = false) { + public function setSelfconsumecell($card_id, $is_openid = false, $need_verify_cod = false, $need_remark_amount = false) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -730,7 +758,8 @@ public function setSelfconsumecell($card_id, $is_openid = false, $need_verify_co * @param bool $is_openid * @return bool|mixed */ - public function setPaycell($card_id, $is_openid = true) { + public function setPaycell($card_id, $is_openid = true) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -756,7 +785,8 @@ public function setPaycell($card_id, $is_openid = true) { * @param array $data * @return bool|array */ - public function setMembercardActivateuserform($data) { + public function setMembercardActivateuserform($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatCustom.php b/Wechat/WechatCustom.php index 0048271..4e6a6ad 100644 --- a/Wechat/WechatCustom.php +++ b/Wechat/WechatCustom.php @@ -5,7 +5,8 @@ use Wechat\Lib\Common; use Wechat\Lib\Tools; -class WechatCustom extends Common { +class WechatCustom extends Common +{ /** 多客服相关地址 */ const CUSTOM_SERVICE_GET_RECORD = '/customservice/getrecord?'; @@ -27,7 +28,8 @@ class WechatCustom extends Common { * @param array $data 数据结构 {"starttime":123456789,"endtime":987654321,"openid":"OPENID","pagesize":10,"pageindex":1,} * @return bool|array */ - public function getCustomServiceMessage($data) { + public function getCustomServiceMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -49,7 +51,8 @@ public function getCustomServiceMessage($data) { * * @return bool|array */ - public function getCustomServiceKFlist() { + public function getCustomServiceKFlist() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -71,7 +74,8 @@ public function getCustomServiceKFlist() { * * @return bool|array */ - public function getCustomServiceOnlineKFlist() { + public function getCustomServiceOnlineKFlist() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -96,7 +100,8 @@ public function getCustomServiceOnlineKFlist() { * @param string $text //附加信息,文本会展示在客服人员的多客服客户端,可为空 * @return bool|array */ - public function createKFSession($openid, $kf_account, $text = '') { + public function createKFSession($openid, $kf_account, $text = '') + { $data = array("openid" => $openid, "kf_account" => $kf_account); if ($text) { $data["text"] = $text; @@ -129,7 +134,8 @@ public function createKFSession($openid, $kf_account, $text = '') { * "errmsg": "ok", * } */ - public function closeKFSession($openid, $kf_account, $text = '') { + public function closeKFSession($openid, $kf_account, $text = '') + { $data = array("openid" => $openid, "kf_account" => $kf_account); if ($text) { $data["text"] = $text; @@ -161,7 +167,8 @@ public function closeKFSession($openid, $kf_account, $text = '') { * "createtime": 123456789, //会话接入时间 * } */ - public function getKFSession($openid) { + public function getKFSession($openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -195,7 +202,8 @@ public function getKFSession($openid) { * ) * ) */ - public function getKFSessionlist($kf_account) { + public function getKFSessionlist($kf_account) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -216,7 +224,8 @@ public function getKFSessionlist($kf_account) { * 获取未接入会话列表 * @return bool|array */ - public function getKFSessionWait() { + public function getKFSessionWait() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -241,7 +250,8 @@ public function getKFSessionWait() { * @param string $password 客服账号明文登录密码,会自动加密 * @return bool|array */ - public function addKFAccount($account, $nickname, $password) { + public function addKFAccount($account, $nickname, $password) + { $data = array("kf_account" => $account, "nickname" => $nickname, "password" => md5($password)); if (!$this->access_token && !$this->getAccessToken()) { return false; @@ -272,7 +282,8 @@ public function addKFAccount($account, $nickname, $password) { * "errmsg": "ok", * } */ - public function updateKFAccount($account, $nickname, $password) { + public function updateKFAccount($account, $nickname, $password) + { $data = array("kf_account" => $account, "nickname" => $nickname, "password" => md5($password)); if (!$this->access_token && !$this->getAccessToken()) { return false; @@ -295,7 +306,8 @@ public function updateKFAccount($account, $nickname, $password) { * @param string $account 完整客服账号(账号前缀@公众号微信号,账号前缀最多10个字符) * @return bool|array */ - public function deleteKFAccount($account) { + public function deleteKFAccount($account) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -318,7 +330,8 @@ public function deleteKFAccount($account) { * @param string $imgfile 头像文件完整路径,如:'D:\user.jpg'。头像文件必须JPG格式,像素建议640*640 * @return bool|array */ - public function setKFHeadImg($account, $imgfile) { + public function setKFHeadImg($account, $imgfile) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatDevice.php b/Wechat/WechatDevice.php index 8126f94..84e504d 100644 --- a/Wechat/WechatDevice.php +++ b/Wechat/WechatDevice.php @@ -10,7 +10,8 @@ * @author Anyon * @date 2016-08-22 10:35 */ -class WechatDevice extends Common { +class WechatDevice extends Common +{ const SHAKEAROUND_DEVICE_APPLYID = '/shakearound/device/applyid?'; //申请设备ID const SHAKEAROUND_DEVICE_APPLYSTATUS = '/shakearound/device/applystatus?'; //查询设备ID申请审核状态 @@ -33,7 +34,8 @@ class WechatDevice extends Common { * @param array $data * @return bool|array */ - public function applyShakeAroundDevice($data) { + public function applyShakeAroundDevice($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -55,7 +57,8 @@ public function applyShakeAroundDevice($data) { * @param int $apply_id * @return bool|array */ - public function applyStatusShakeAroundDevice($apply_id) { + public function applyStatusShakeAroundDevice($apply_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -78,7 +81,8 @@ public function applyStatusShakeAroundDevice($apply_id) { * @param array $data * @return bool */ - public function updateShakeAroundDevice($data) { + public function updateShakeAroundDevice($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -101,7 +105,8 @@ public function updateShakeAroundDevice($data) { * @param $data * @return bool|array */ - public function searchShakeAroundDevice($data) { + public function searchShakeAroundDevice($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -127,7 +132,8 @@ public function searchShakeAroundDevice($data) { * @param int $minor * @return bool|array */ - public function bindLocationShakeAroundDevice($device_id, $poi_id, $uuid = '', $major = 0, $minor = 0) { + public function bindLocationShakeAroundDevice($device_id, $poi_id, $uuid = '', $major = 0, $minor = 0) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -162,7 +168,8 @@ public function bindLocationShakeAroundDevice($device_id, $poi_id, $uuid = '', $ * @param type $poi_appid 目标微信appid * @return boolean */ - public function bindLocationOtherShakeAroundDevice($device_identifier, $poi_id, $poi_appid) { + public function bindLocationOtherShakeAroundDevice($device_identifier, $poi_id, $poi_appid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -191,7 +198,8 @@ public function bindLocationOtherShakeAroundDevice($device_identifier, $poi_id, * @param int $minor * @return bool|array */ - public function bindPageShakeAroundDevice($device_id, $page_ids = array(), $bind = 1, $append = 1, $uuid = '', $major = 0, $minor = 0) { + public function bindPageShakeAroundDevice($device_id, $page_ids = array(), $bind = 1, $append = 1, $uuid = '', $major = 0, $minor = 0) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -223,7 +231,8 @@ public function bindPageShakeAroundDevice($device_id, $page_ids = array(), $bind * @param array $data {"media":'@Path\filename.jpg'} * @return bool|array */ - public function uploadShakeAroundMedia($data) { + public function uploadShakeAroundMedia($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -250,7 +259,8 @@ public function uploadShakeAroundMedia($data) { * @param string $comment 页面的备注信息,不超过15 个字,可不填 * @return bool|array */ - public function addShakeAroundPage($title, $description, $icon_url, $page_url, $comment = '') { + public function addShakeAroundPage($title, $description, $icon_url, $page_url, $comment = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -279,7 +289,8 @@ public function addShakeAroundPage($title, $description, $icon_url, $page_url, $ * @param string $comment 页面的备注信息,不超过15 个字,可不填 * @return bool|array */ - public function updateShakeAroundPage($page_id, $title, $description, $icon_url, $page_url, $comment = '') { + public function updateShakeAroundPage($page_id, $title, $description, $icon_url, $page_url, $comment = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -305,7 +316,8 @@ public function updateShakeAroundPage($page_id, $title, $description, $icon_url, * @param int $count * @return bool|mixed */ - public function searchShakeAroundPage($page_ids = array(), $begin = 0, $count = 1) { + public function searchShakeAroundPage($page_ids = array(), $begin = 0, $count = 1) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -333,7 +345,8 @@ public function searchShakeAroundPage($page_ids = array(), $begin = 0, $count = * @param array $page_ids * @return bool|array */ - public function deleteShakeAroundPage($page_ids = array()) { + public function deleteShakeAroundPage($page_ids = array()) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -357,7 +370,8 @@ public function deleteShakeAroundPage($page_ids = array()) { * @param string $ticket 摇周边业务的ticket(可在摇到的URL中得到,ticket生效时间为30 分钟) * @return bool|array */ - public function getShakeInfoShakeAroundUser($ticket) { + public function getShakeInfoShakeAroundUser($ticket) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -386,7 +400,8 @@ public function getShakeInfoShakeAroundUser($ticket) { * @param int $minor * @return bool|array */ - public function deviceShakeAroundStatistics($device_id, $begin_date, $end_date, $uuid = '', $major = 0, $minor = 0) { + public function deviceShakeAroundStatistics($device_id, $begin_date, $end_date, $uuid = '', $major = 0, $minor = 0) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -420,7 +435,8 @@ public function deviceShakeAroundStatistics($device_id, $begin_date, $end_date, * @param int $end_date 结束日期时间戳,最长时间跨度为30 天 * @return bool|array */ - public function pageShakeAroundStatistics($page_id, $begin_date, $end_date) { + public function pageShakeAroundStatistics($page_id, $begin_date, $end_date) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatExtends.php b/Wechat/WechatExtends.php index 6a8e6ca..c91f664 100644 --- a/Wechat/WechatExtends.php +++ b/Wechat/WechatExtends.php @@ -11,7 +11,8 @@ * @author Anyon * @date 2016-08-22 10:32 */ -class WechatExtends extends Common { +class WechatExtends extends Common +{ const QR_LIMIT_SCENE = 1; @@ -56,7 +57,8 @@ class WechatExtends extends Common { * @param string $ticket 传入由getQRCode方法生成的ticket参数 * @return string url 返回http地址 */ - public function getQRUrl($ticket) { + public function getQRUrl($ticket) + { return self::QRCODE_IMG_URL . urlencode($ticket); } @@ -65,7 +67,8 @@ public function getQRUrl($ticket) { * @param string $long_url 传入要转换的长url * @return bool|string url 成功则返回转换后的短url */ - public function getShortUrl($long_url) { + public function getShortUrl($long_url) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -93,7 +96,8 @@ public function getShortUrl($long_url) { * @param int $expire 临时二维码有效期,最大为2592000秒(30天) * @return bool|array ('ticket'=>'qrcode字串','expire_seconds'=>2592000,'url'=>'二维码图片解析后的地址') */ - public function getQRCode($scene_id, $type = 0, $expire = 2592000) { + public function getQRCode($scene_id, $type = 0, $expire = 2592000) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -130,7 +134,8 @@ public function getQRCode($scene_id, $type = 0, $expire = 2592000) { * @param string $region 区域名称,在城市存在的情况下可省略;与经纬度二选一传入 * @return bool|array */ - public function querySemantic($uid, $query, $category, $latitude = 0.00, $longitude = 0.00, $city = "", $region = "") { + public function querySemantic($uid, $query, $category, $latitude = 0.00, $longitude = 0.00, $city = "", $region = "") + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -170,7 +175,8 @@ public function querySemantic($uid, $query, $category, $latitude = 0.00, $longit * @param string $end_date 结束时间 * @return bool|array 成功返回查询结果数组,其定义请看官方文档 */ - public function getDatacube($type, $subtype, $begin_date, $end_date = '') { + public function getDatacube($type, $subtype, $begin_date, $end_date = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatHardware.php b/Wechat/WechatHardware.php index 121f61f..1605b2f 100644 --- a/Wechat/WechatHardware.php +++ b/Wechat/WechatHardware.php @@ -5,7 +5,8 @@ use Wechat\Lib\Common; use Wechat\Lib\Tools; -class WechatHardware extends Common { +class WechatHardware extends Common +{ const DEVICE_AUTHORIZE_DEVICE = '/device/authorize_device?'; //设备设全 const DEVICE_GETQRCODE = '/device/getqrcode?'; //设备授权新接口 @@ -19,7 +20,8 @@ class WechatHardware extends Common { * @param $data * @return bool|mixed */ - public function deviceCompelUnbindhttps($data) { + public function deviceCompelUnbindhttps($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -37,7 +39,8 @@ public function deviceCompelUnbindhttps($data) { } - public function transmsg($data) { + public function transmsg($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -55,7 +58,8 @@ public function transmsg($data) { return false; } - public function getQrcode($product_id) { + public function getQrcode($product_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -77,7 +81,8 @@ public function getQrcode($product_id) { * @param $data * @return bool|mixed */ - public function deviceAuthorize($data) { + public function deviceAuthorize($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -99,7 +104,8 @@ public function deviceAuthorize($data) { * @param $data * @return bool|mixed */ - public function getDeviceQrcode($data) { + public function getDeviceQrcode($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -122,7 +128,8 @@ public function getDeviceQrcode($data) { * @param $device_id * @return bool|mixed */ - public function getDeviceStat($device_id) { + public function getDeviceStat($device_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatMedia.php b/Wechat/WechatMedia.php index 3fff166..045eb17 100644 --- a/Wechat/WechatMedia.php +++ b/Wechat/WechatMedia.php @@ -11,7 +11,8 @@ * @author Anyon * @date 2016/10/26 14:47 */ -class WechatMedia extends Common { +class WechatMedia extends Common +{ const UPLOAD_MEDIA_URL = 'http://file.api.weixin.qq.com/cgi-bin'; const MEDIA_UPLOAD_URL = '/media/upload?'; @@ -36,7 +37,8 @@ class WechatMedia extends Common { * @param string $type 类型:图片:image 语音:voice 视频:video 缩略图:thumb * @return bool|array */ - public function uploadMedia($data, $type) { + public function uploadMedia($data, $type) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -60,7 +62,8 @@ public function uploadMedia($data, $type) { * @param bool $is_video 是否为视频文件,默认为否 * @return bool|array */ - public function getMedia($media_id, $is_video = false) { + public function getMedia($media_id, $is_video = false) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -88,7 +91,8 @@ public function getMedia($media_id, $is_video = false) { * @param bool $is_video 是否为视频文件,默认为否 * @return bool|array */ - public function getMediaWithHttpInfo($media_id, $is_video = false) { + public function getMediaWithHttpInfo($media_id, $is_video = false) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -97,9 +101,9 @@ public function getMediaWithHttpInfo($media_id, $is_video = false) { $url_prefix = $is_video ? str_replace('https', 'http', self::API_URL_PREFIX) : self::API_URL_PREFIX; $url = $url_prefix . self::MEDIA_GET_URL . "access_token={$this->access_token}" . '&media_id=' . $media_id; $oCurl = curl_init(); - if (stripos($url, "https://") !== FALSE) { - curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE); + if (stripos($url, "https://") !== false) { + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); } curl_setopt($oCurl, CURLOPT_URL, $url); @@ -136,7 +140,8 @@ public function getMediaWithHttpInfo($media_id, $is_video = false) { * @param array $data {"media":'@Path\filename.jpg'} * @return bool|array */ - public function uploadImg($data) { + public function uploadImg($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -165,7 +170,8 @@ public function uploadImg($data) { * @param array $video_info 视频信息数组,非视频素材不需要提供 array('title'=>'视频标题','introduction'=>'描述') * @return bool|array */ - public function uploadForeverMedia($data, $type, $is_video = false, $video_info = array()) { + public function uploadForeverMedia($data, $type, $is_video = false, $video_info = array()) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -191,7 +197,8 @@ public function uploadForeverMedia($data, $type, $is_video = false, $video_info * @param array $data 消息结构{"articles":[{...}]} * @return bool|array */ - public function uploadForeverArticles($data) { + public function uploadForeverArticles($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -216,7 +223,8 @@ public function uploadForeverArticles($data) { * @param int $index 更新的文章在图文素材的位置,第一篇为0,仅多图文使用 * @return bool|array */ - public function updateForeverArticles($media_id, $data, $index = 0) { + public function updateForeverArticles($media_id, $data, $index = 0) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -246,7 +254,8 @@ public function updateForeverArticles($media_id, $data, $index = 0) { * @param bool $is_video 是否为视频文件,默认为否 * @return bool|array|raw data */ - public function getForeverMedia($media_id, $is_video = false) { + public function getForeverMedia($media_id, $is_video = false) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -279,7 +288,8 @@ public function getForeverMedia($media_id, $is_video = false) { * @param string $media_id 媒体文件id * @return bool */ - public function delForeverMedia($media_id) { + public function delForeverMedia($media_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -310,7 +320,8 @@ public function delForeverMedia($media_id) { * 'item'=>array() //素材列表数组,内容定义请参考官方文档 * ) */ - public function getForeverList($type, $offset, $count) { + public function getForeverList($type, $offset, $count) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -343,7 +354,8 @@ public function getForeverList($type, $offset, $count) { * 'news_count'=>0 //图文总数量 * ) */ - public function getForeverCount() { + public function getForeverCount() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -365,7 +377,8 @@ public function getForeverCount() { * @param array $data 消息结构{"articles":[{...}]} * @return bool|array */ - public function uploadArticles($data) { + public function uploadArticles($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -397,7 +410,8 @@ public function uploadArticles($data) { * "created_at":1398848981 * } */ - public function uploadMpVideo($data) { + public function uploadMpVideo($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatMenu.php b/Wechat/WechatMenu.php index e870456..5d2e12b 100644 --- a/Wechat/WechatMenu.php +++ b/Wechat/WechatMenu.php @@ -11,7 +11,8 @@ * @author Anyon * @date 2016/06/28 11:52 */ -class WechatMenu extends Common { +class WechatMenu extends Common +{ /** 创建自定义菜单 */ const MENU_ADD_URL = '/menu/create?'; @@ -33,7 +34,8 @@ class WechatMenu extends Common { * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141013&token=&lang=zh_CN 文档 * @return bool */ - public function createMenu($data) { + public function createMenu($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -54,7 +56,8 @@ public function createMenu($data) { * 获取所有菜单 * @return bool|array */ - public function getMenu() { + public function getMenu() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -75,7 +78,8 @@ public function getMenu() { * 删除所有菜单 * @return bool */ - public function deleteMenu() { + public function deleteMenu() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -98,7 +102,8 @@ public function deleteMenu() { * @link https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1455782296&token=&lang=zh_CN 文档 * @return bool|string */ - public function createCondMenu($data) { + public function createCondMenu($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -120,7 +125,8 @@ public function createCondMenu($data) { * @param string $menuid 菜单ID * @return bool */ - public function deleteCondMenu($menuid) { + public function deleteCondMenu($menuid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -143,7 +149,8 @@ public function deleteCondMenu($menuid) { * @param string $openid 粉丝openid * @return bool */ - public function tryCondMenu($openid) { + public function tryCondMenu($openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatOauth.php b/Wechat/WechatOauth.php index 8f5f149..0bbaa7f 100644 --- a/Wechat/WechatOauth.php +++ b/Wechat/WechatOauth.php @@ -8,7 +8,8 @@ /** * 微信网页授权 */ -class WechatOauth extends Common { +class WechatOauth extends Common +{ const OAUTH_PREFIX = 'https://open.weixin.qq.com/connect/oauth2'; const OAUTH_AUTHORIZE_URL = '/authorize?'; @@ -24,7 +25,8 @@ class WechatOauth extends Common { * @param string $scope 授权类类型(可选值snsapi_base|snsapi_userinfo) * @return string */ - public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base') { + public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base') + { $redirect_uri = urlencode($callback); return self::OAUTH_PREFIX . self::OAUTH_AUTHORIZE_URL . "appid={$this->appid}&redirect_uri={$redirect_uri}&response_type=code&scope={$scope}&state={$state}#wechat_redirect"; } @@ -33,7 +35,8 @@ public function getOauthRedirect($callback, $state = '', $scope = 'snsapi_base') * 通过 code 获取 AccessToken 和 openid * @return bool|array */ - public function getOauthAccessToken() { + public function getOauthAccessToken() + { $code = isset($_GET['code']) ? $_GET['code'] : ''; if (empty($code)) { Tools::log("getOauthAccessToken Fail, Because there is no access to the code value in get."); @@ -58,7 +61,8 @@ public function getOauthAccessToken() { * @param string $refresh_token * @return bool|array */ - public function getOauthRefreshToken($refresh_token) { + public function getOauthRefreshToken($refresh_token) + { $result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_REFRESH_URL . "appid={$this->appid}&grant_type=refresh_token&refresh_token={$refresh_token}"); if ($result) { $json = json_decode($result, true); @@ -80,7 +84,8 @@ public function getOauthRefreshToken($refresh_token) { * @return bool|array {openid,nickname,sex,province,city,country,headimgurl,privilege,[unionid]} * 注意:unionid字段 只有在用户将公众号绑定到微信开放平台账号后,才会出现。建议调用前用isset()检测一下 */ - public function getOauthUserInfo($access_token, $openid) { + public function getOauthUserInfo($access_token, $openid) + { $result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_USERINFO_URL . "access_token={$access_token}&openid={$openid}"); if ($result) { $json = json_decode($result, true); @@ -101,7 +106,8 @@ public function getOauthUserInfo($access_token, $openid) { * @param string $openid * @return bool 是否有效 */ - public function getOauthAuth($access_token, $openid) { + public function getOauthAuth($access_token, $openid) + { $result = Tools::httpGet(self::API_BASE_URL_PREFIX . self::OAUTH_AUTH_URL . "access_token={$access_token}&openid={$openid}"); if ($result) { $json = json_decode($result, true); diff --git a/Wechat/WechatPay.php b/Wechat/WechatPay.php index 8978d11..8b2a566 100644 --- a/Wechat/WechatPay.php +++ b/Wechat/WechatPay.php @@ -9,7 +9,8 @@ * @author zoujingli * @date 2015/05/13 12:12:00 */ -class WechatPay { +class WechatPay +{ /** 支付接口基础地址 */ const MCH_BASE_URL = 'https://api.mch.weixin.qq.com'; @@ -35,7 +36,8 @@ class WechatPay { * WechatPay constructor. * @param array $options */ - public function __construct($options = array()) { + public function __construct($options = array()) + { $config = Loader::config($options); $this->appid = isset($config['appid']) ? $config['appid'] : ''; $this->mch_id = isset($config['mch_id']) ? $config['mch_id'] : ''; @@ -49,7 +51,8 @@ public function __construct($options = array()) { * @param array $data * @return string */ - protected function createXml($data) { + protected function createXml($data) + { if (!isset($data['wxappid']) && !isset($data['mch_appid']) && !isset($data['appid'])) { $data['appid'] = $this->appid; } @@ -67,7 +70,8 @@ protected function createXml($data) { * @param string $url * @return mixed */ - public function postXml($data, $url) { + public function postXml($data, $url) + { return Tools::httpPost($url, $this->createXml($data)); } @@ -77,7 +81,8 @@ public function postXml($data, $url) { * @param string $url * @return mixed */ - function postXmlSSL($data, $url) { + function postXmlSSL($data, $url) + { return Tools::httpsPost($url, $this->createXml($data), $this->ssl_cer, $this->ssl_key); } @@ -88,7 +93,8 @@ function postXmlSSL($data, $url) { * @param string $method * @return array */ - public function getArrayResult($data, $url, $method = 'postXml') { + public function getArrayResult($data, $url, $method = 'postXml') + { return Tools::xml2arr($this->$method($data, $url)); } @@ -97,7 +103,8 @@ public function getArrayResult($data, $url, $method = 'postXml') { * @param array $result * @return bool|array */ - protected function _parseResult($result) { + protected function _parseResult($result) + { if (empty($result)) { $this->errCode = 'result error'; $this->errMsg = '解析返回结果失败'; @@ -125,7 +132,8 @@ protected function _parseResult($result) { * @param null $goods_tag 商品标签 * @return array|bool */ - public function createMicroPay($auth_code, $out_trade_no, $total_fee, $body, $goods_tag = null) { + public function createMicroPay($auth_code, $out_trade_no, $total_fee, $body, $goods_tag = null) + { $data = array( "appid" => $this->appid, "mch_id" => $this->mch_id, @@ -147,7 +155,8 @@ public function createMicroPay($auth_code, $out_trade_no, $total_fee, $body, $go * 支付通知验证处理 * @return bool|array */ - public function getNotify() { + public function getNotify() + { $notifyInfo = (array)simplexml_load_string(file_get_contents("php://input"), 'SimpleXMLElement', LIBXML_NOCDATA); if (empty($notifyInfo)) { Tools::log('Payment notification forbidden access.', 'ERR'); @@ -182,7 +191,8 @@ public function getNotify() { * @param bool $isReturn 是否返回XML内容,默认不返回 * @return string */ - public function replyXml(array $data, $isReturn = false) { + public function replyXml(array $data, $isReturn = false) + { $xml = Tools::arr2xml($data); if ($isReturn) { return $xml; @@ -203,7 +213,8 @@ public function replyXml(array $data, $isReturn = false) { * @param string $fee_type 交易币种 * @return bool|string */ - public function getPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_url, $trade_type = "JSAPI", $goods_tag = null, $fee_type = 'CNY') { + public function getPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_url, $trade_type = "JSAPI", $goods_tag = null, $fee_type = 'CNY') + { $postdata = array( "body" => $body, "out_trade_no" => $out_trade_no, @@ -233,7 +244,8 @@ public function getPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_u * @param string $fee_type 交易币种 * @return bool|string */ - public function getQrcPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_url, $goods_tag = null, $fee_type = 'CNY') { + public function getQrcPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_url, $goods_tag = null, $fee_type = 'CNY') + { $postdata = array( "body" => $body, "out_trade_no" => $out_trade_no, @@ -257,7 +269,8 @@ public function getQrcPrepayId($openid, $body, $out_trade_no, $total_fee, $notif * @param string $product_id 商户定义的商品id 或者订单号 * @return string */ - public function getQrcPayUrl($product_id) { + public function getQrcPayUrl($product_id) + { $data = array( 'appid' => $this->appid, 'mch_id' => $this->mch_id, @@ -275,7 +288,8 @@ public function getQrcPayUrl($product_id) { * @param string $prepay_id * @return array */ - public function createMchPay($prepay_id) { + public function createMchPay($prepay_id) + { $option = array(); $option["appId"] = $this->appid; $option["timeStamp"] = (string)time(); @@ -292,7 +306,8 @@ public function createMchPay($prepay_id) { * @param string $out_trade_no * @return bool */ - public function closeOrder($out_trade_no) { + public function closeOrder($out_trade_no) + { $data = array('out_trade_no' => $out_trade_no); $result = $this->getArrayResult($data, self::MCH_BASE_URL . '/pay/closeorder'); if (false === $this->_parseResult($result)) { @@ -306,7 +321,8 @@ public function closeOrder($out_trade_no) { * @param $out_trade_no * @return bool|array */ - public function queryOrder($out_trade_no) { + public function queryOrder($out_trade_no) + { $data = array('out_trade_no' => $out_trade_no); $result = $this->getArrayResult($data, self::MCH_BASE_URL . '/pay/orderquery'); if (false === $this->_parseResult($result)) { @@ -329,7 +345,8 @@ public function queryOrder($out_trade_no) { * REFUND_SOURCE_RECHARGE_FUNDS --- 可用余额退款 * @return bool */ - public function refund($out_trade_no, $transaction_id, $out_refund_no, $total_fee, $refund_fee, $op_user_id = null, $refund_account = '') { + public function refund($out_trade_no, $transaction_id, $out_refund_no, $total_fee, $refund_fee, $op_user_id = null, $refund_account = '') + { $data = array(); $data['out_trade_no'] = $out_trade_no; $data['transaction_id'] = $transaction_id; @@ -350,7 +367,8 @@ public function refund($out_trade_no, $transaction_id, $out_refund_no, $total_fe * @param string $out_trade_no * @return bool|array */ - public function refundQuery($out_trade_no) { + public function refundQuery($out_trade_no) + { $data = array(); $data['out_trade_no'] = $out_trade_no; $result = $this->getArrayResult($data, self::MCH_BASE_URL . '/pay/refundquery'); @@ -366,7 +384,8 @@ public function refundQuery($out_trade_no) { * @param string $bill_type ALL|SUCCESS|REFUND|REVOKED * @return bool|array */ - public function getBill($bill_date, $bill_type = 'ALL') { + public function getBill($bill_date, $bill_type = 'ALL') + { $data = array(); $data['bill_date'] = $bill_date; $data['bill_type'] = $bill_type; @@ -394,7 +413,8 @@ public function getBill($bill_date, $bill_type = 'ALL') { * @return array|bool * @link https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5 */ - public function sendRedPack($openid, $total_amount, $mch_billno, $sendname, $wishing, $act_name, $remark, $total_num = 1, $scene_id = null, $risk_info = '', $consume_mch_id = null) { + public function sendRedPack($openid, $total_amount, $mch_billno, $sendname, $wishing, $act_name, $remark, $total_num = 1, $scene_id = null, $risk_info = '', $consume_mch_id = null) + { $data = array(); $data['mch_billno'] = $mch_billno; // 商户订单号 mch_id+yyyymmdd+10位一天内不能重复的数字 $data['wxappid'] = $this->appid; @@ -431,7 +451,8 @@ public function sendRedPack($openid, $total_amount, $mch_billno, $sendname, $wis * @return bool|array * @link https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_7&index=6 */ - public function queryRedPack($billno) { + public function queryRedPack($billno) + { $data['mch_billno'] = $billno; $data['bill_type'] = 'MCHT'; $result = $this->postXmlSSL($data, self::MCH_BASE_URL . '/mmpaymkttransfers/gethbinfo'); @@ -451,7 +472,8 @@ public function queryRedPack($billno) { * @return bool|array * @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2 */ - public function transfers($openid, $amount, $billno, $desc) { + public function transfers($openid, $amount, $billno, $desc) + { $data = array(); $data['mchid'] = $this->mch_id; $data['mch_appid'] = $this->appid; @@ -475,7 +497,8 @@ public function transfers($openid, $amount, $billno, $desc) { * @return bool|array * @link https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3 */ - public function queryTransfers($billno) { + public function queryTransfers($billno) + { $data['appid'] = $this->appid; $data['mch_id'] = $this->mch_id; $data['partner_trade_no'] = $billno; @@ -492,7 +515,8 @@ public function queryTransfers($billno) { * @param string $url 需要处理的长链接 * @return bool|string */ - public function shortUrl($url) { + public function shortUrl($url) + { $data = array(); $data['long_url'] = $url; $result = $this->getArrayResult($data, self::MCH_BASE_URL . '/tools/shorturl'); @@ -518,7 +542,8 @@ public function shortUrl($url) { * @return bool|array * @link https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3 */ - public function sendCoupon($coupon_stock_id, $partner_trade_no, $openid, $op_user_id = null) { + public function sendCoupon($coupon_stock_id, $partner_trade_no, $openid, $op_user_id = null) + { $data = array(); $data['appid'] = $this->appid; $data['coupon_stock_id'] = $coupon_stock_id; diff --git a/Wechat/WechatPoi.php b/Wechat/WechatPoi.php index 1bce669..72fd2c1 100644 --- a/Wechat/WechatPoi.php +++ b/Wechat/WechatPoi.php @@ -10,7 +10,8 @@ * @author Anyon * @date 2016/10/26 15:43 */ -class WechatPoi extends Common { +class WechatPoi extends Common +{ /** 创建门店 */ const POI_ADD = '/cgi-bin/poi/addpoi?'; @@ -36,7 +37,8 @@ class WechatPoi extends Common { * @param array $data * @return bool */ - public function addPoi($data) { + public function addPoi($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -59,7 +61,8 @@ public function addPoi($data) { * @param string $poi_id JSON数据格式 * @return bool|array */ - public function delPoi($poi_id) { + public function delPoi($poi_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -83,7 +86,8 @@ public function delPoi($poi_id) { * @param array $data * @return bool */ - public function updatePoi($data) { + public function updatePoi($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -106,7 +110,8 @@ public function updatePoi($data) { * @param string $poi_id * @return bool */ - public function getPoi($poi_id) { + public function getPoi($poi_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -131,7 +136,8 @@ public function getPoi($poi_id) { * @param int $limit 返回数据条数,最大允许50,默认为20 * @return bool|array */ - public function getPoiList($begin = 0, $limit = 50) { + public function getPoiList($begin = 0, $limit = 50) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -154,7 +160,8 @@ public function getPoiList($begin = 0, $limit = 50) { * 获取商家门店类目表 * @return bool|string */ - public function getCategory() { + public function getCategory() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/Wechat/WechatReceive.php b/Wechat/WechatReceive.php index 1c33199..8d11390 100644 --- a/Wechat/WechatReceive.php +++ b/Wechat/WechatReceive.php @@ -12,7 +12,8 @@ * @author Anyon * @date 2016/06/28 11:29 */ -class WechatReceive extends Common { +class WechatReceive extends Common +{ /** 消息推送地址 */ const CUSTOM_SEND_URL = '/message/custom/send?'; @@ -46,7 +47,8 @@ class WechatReceive extends Common { * 获取微信服务器发来的内容 * @return $this */ - public function getRev() { + public function getRev() + { if ($this->_receive) { return $this; } @@ -59,7 +61,8 @@ public function getRev() { * 获取微信服务器发来的信息数据 * @return array */ - public function getRevData() { + public function getRevData() + { return $this->_receive; } @@ -67,7 +70,8 @@ public function getRevData() { * 获取消息发送者 * @return bool|string */ - public function getRevFrom() { + public function getRevFrom() + { if (isset($this->_receive['FromUserName'])) { return $this->_receive['FromUserName']; } @@ -78,7 +82,8 @@ public function getRevFrom() { * 获取消息接受者 * @return bool|string */ - public function getRevTo() { + public function getRevTo() + { if (isset($this->_receive['ToUserName'])) { return $this->_receive['ToUserName']; } @@ -89,7 +94,8 @@ public function getRevTo() { * 获取接收消息的类型 * @return bool|string */ - public function getRevType() { + public function getRevType() + { if (isset($this->_receive['MsgType'])) { return $this->_receive['MsgType']; } @@ -100,7 +106,8 @@ public function getRevType() { * 获取消息ID * @return bool|string */ - public function getRevID() { + public function getRevID() + { if (isset($this->_receive['MsgId'])) { return $this->_receive['MsgId']; } @@ -111,7 +118,8 @@ public function getRevID() { * 获取消息发送时间 * @return bool|string */ - public function getRevCtime() { + public function getRevCtime() + { if (isset($this->_receive['CreateTime'])) { return $this->_receive['CreateTime']; } @@ -123,7 +131,8 @@ public function getRevCtime() { * 当Event为 card_pass_check(审核通过) 或 card_not_pass_check(未通过) * @return bool|string 返回卡券ID */ - public function getRevCardPass() { + public function getRevCardPass() + { if (isset($this->_receive['CardId'])) { return $this->_receive['CardId']; } @@ -135,7 +144,8 @@ public function getRevCardPass() { * 当Event为 user_get_card(用户领取卡券) * @return bool|array */ - public function getRevCardGet() { + public function getRevCardGet() + { $array = array(); if (isset($this->_receive['CardId'])) { $array['CardId'] = $this->_receive['CardId']; @@ -158,7 +168,8 @@ public function getRevCardGet() { * 当Event为 user_del_card(用户删除卡券) * @return bool|array */ - public function getRevCardDel() { + public function getRevCardDel() + { if (isset($this->_receive['CardId'])) { //卡券 ID $array['CardId'] = $this->_receive['CardId']; } @@ -175,7 +186,8 @@ public function getRevCardDel() { * 获取接收消息内容正文 * @return bool */ - public function getRevContent() { + public function getRevContent() + { if (isset($this->_receive['Content'])) { return $this->_receive['Content']; } else if (isset($this->_receive['Recognition'])) { //获取语音识别文字内容,需申请开通 @@ -188,7 +200,8 @@ public function getRevContent() { * 获取接收消息图片 * @return array|bool */ - public function getRevPic() { + public function getRevPic() + { if (isset($this->_receive['PicUrl'])) { return array( 'mediaid' => $this->_receive['MediaId'], @@ -202,7 +215,8 @@ public function getRevPic() { * 获取接收消息链接 * @return bool|array */ - public function getRevLink() { + public function getRevLink() + { if (isset($this->_receive['Url'])) { return array( 'url' => $this->_receive['Url'], @@ -217,7 +231,8 @@ public function getRevLink() { * 获取接收地理位置 * @return bool|array */ - public function getRevGeo() { + public function getRevGeo() + { if (isset($this->_receive['Location_X'])) { return array( 'x' => $this->_receive['Location_X'], @@ -233,7 +248,8 @@ public function getRevGeo() { * 获取上报地理位置事件 * @return bool|array */ - public function getRevEventGeo() { + public function getRevEventGeo() + { if (isset($this->_receive['Latitude'])) { return array( 'x' => $this->_receive['Latitude'], @@ -248,7 +264,8 @@ public function getRevEventGeo() { * 获取接收事件推送 * @return bool|array */ - public function getRevEvent() { + public function getRevEvent() + { if (isset($this->_receive['Event'])) { $array['event'] = $this->_receive['Event']; } @@ -269,7 +286,8 @@ public function getRevEvent() { * Event 事件类型,scancode_waitmsg * @return bool|array */ - public function getRevScanInfo() { + public function getRevScanInfo() + { if (isset($this->_receive['ScanCodeInfo'])) { if (!is_array($this->_receive['ScanCodeInfo'])) { $array = (array)$this->_receive['ScanCodeInfo']; @@ -304,7 +322,8 @@ public function getRevScanInfo() { * ) * */ - public function getRevSendPicsInfo() { + public function getRevSendPicsInfo() + { if (isset($this->_receive['SendPicsInfo'])) { if (!is_array($this->_receive['SendPicsInfo'])) { $array = (array)$this->_receive['SendPicsInfo']; @@ -343,7 +362,8 @@ public function getRevSendPicsInfo() { * ) * */ - public function getRevSendGeoInfo() { + public function getRevSendGeoInfo() + { if (isset($this->_receive['SendLocationInfo'])) { if (!is_array($this->_receive['SendLocationInfo'])) { $array = (array)$this->_receive['SendLocationInfo']; @@ -368,7 +388,8 @@ public function getRevSendGeoInfo() { * 获取接收语音推送 * @return bool|array */ - public function getRevVoice() { + public function getRevVoice() + { if (isset($this->_receive['MediaId'])) { return array( 'mediaid' => $this->_receive['MediaId'], @@ -382,7 +403,8 @@ public function getRevVoice() { * 获取接收视频推送 * @return array|bool */ - public function getRevVideo() { + public function getRevVideo() + { if (isset($this->_receive['MediaId'])) { return array( 'mediaid' => $this->_receive['MediaId'], @@ -396,7 +418,8 @@ public function getRevVideo() { * 获取接收TICKET * @return bool|string */ - public function getRevTicket() { + public function getRevTicket() + { if (isset($this->_receive['Ticket'])) { return $this->_receive['Ticket']; } @@ -407,7 +430,8 @@ public function getRevTicket() { * 获取二维码的场景值 * @return bool|string */ - public function getRevSceneId() { + public function getRevSceneId() + { if (isset($this->_receive['EventKey'])) { return str_replace('qrscene_', '', $this->_receive['EventKey']); } @@ -420,7 +444,8 @@ public function getRevSceneId() { * 当Event为 MASSSENDJOBFINISH 或 TEMPLATESENDJOBFINISH * @return bool|string */ - public function getRevTplMsgID() { + public function getRevTplMsgID() + { if (isset($this->_receive['MsgID'])) { return $this->_receive['MsgID']; } @@ -431,7 +456,8 @@ public function getRevTplMsgID() { * 获取模板消息发送状态 * @return bool|string */ - public function getRevStatus() { + public function getRevStatus() + { if (isset($this->_receive['Status'])) { return $this->_receive['Status']; } @@ -443,7 +469,8 @@ public function getRevStatus() { * 当Event为 MASSSENDJOBFINISH 或 TEMPLATESENDJOBFINISH,即高级群发/模板消息 * @return bool|array */ - public function getRevResult() { + public function getRevResult() + { if (isset($this->_receive['Status'])) { //发送是否成功,具体的返回值请参考 高级群发/模板消息 的事件推送说明 $array['Status'] = $this->_receive['Status']; } @@ -474,7 +501,8 @@ public function getRevResult() { * 当Event为 kfcreatesession 即接入会话 * @return bool|string */ - public function getRevKFCreate() { + public function getRevKFCreate() + { if (isset($this->_receive['KfAccount'])) { return $this->_receive['KfAccount']; } @@ -486,7 +514,8 @@ public function getRevKFCreate() { * 当Event为 kfclosesession 即关闭会话 * @return bool|string */ - public function getRevKFClose() { + public function getRevKFClose() + { if (isset($this->_receive['KfAccount'])) { return $this->_receive['KfAccount']; } @@ -498,7 +527,8 @@ public function getRevKFClose() { * 当Event为 kfswitchsession 即转接会话 * @return bool|array */ - public function getRevKFSwitch() { + public function getRevKFSwitch() + { if (isset($this->_receive['FromKfAccount'])) { //原接入客服 $array['FromKfAccount'] = $this->_receive['FromKfAccount']; } @@ -516,7 +546,8 @@ public function getRevKFSwitch() { * @param array $data 消息结构{"touser":"OPENID","msgtype":"news","news":{...}} * @return bool|array */ - public function sendCustomMessage($data) { + public function sendCustomMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -539,7 +570,8 @@ public function sendCustomMessage($data) { * @param string $id2 同$id1。但如果只有一个行业,此参数可省略 * @return bool|mixed */ - public function setTMIndustry($id1, $id2 = '') { + public function setTMIndustry($id1, $id2 = '') + { if ($id1) { $data['industry_id1'] = $id1; } @@ -568,7 +600,8 @@ public function setTMIndustry($id1, $id2 = '') { * @param string $tpl_id 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式 * @return bool|string */ - public function addTemplateMessage($tpl_id) { + public function addTemplateMessage($tpl_id) + { $data = array('template_id_short' => $tpl_id); if (!$this->access_token && !$this->getAccessToken()) return false; @@ -614,7 +647,8 @@ public function addTemplateMessage($tpl_id) { * } * @return bool|array */ - public function sendTemplateMessage($data) { + public function sendTemplateMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -636,7 +670,8 @@ public function sendTemplateMessage($data) { * @param string $customer_account * @return $this */ - public function transfer_customer_service($customer_account = '') { + public function transfer_customer_service($customer_account = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -667,7 +702,8 @@ public function transfer_customer_service($customer_account = '') { * } * @return bool|array */ - public function sendMassMessage($data) { + public function sendMassMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -701,7 +737,8 @@ public function sendMassMessage($data) { * } * @return bool|array */ - public function sendGroupMassMessage($data) { + public function sendGroupMassMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -723,7 +760,8 @@ public function sendGroupMassMessage($data) { * @param string $msg_id 消息ID * @return bool */ - public function deleteMassMessage($msg_id) { + public function deleteMassMessage($msg_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -755,7 +793,8 @@ public function deleteMassMessage($msg_id) { * } * @return bool|array */ - public function previewMassMessage($data) { + public function previewMassMessage($data) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -781,7 +820,8 @@ public function previewMassMessage($data) { * "msg_status":"SEND_SUCCESS" //消息发送后的状态,SENDING表示正在发送 SEND_SUCCESS表示发送成功 * } */ - public function queryMassMessage($msg_id) { + public function queryMassMessage($msg_id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -804,7 +844,8 @@ public function queryMassMessage($msg_id) { * @param bool $append 是否在原消息数组追加 * @return array */ - public function Message($msg = '', $append = false) { + public function Message($msg = '', $append = false) + { if (is_null($msg)) { $this->_msg = array(); } elseif (is_array($msg)) { @@ -823,7 +864,8 @@ public function Message($msg = '', $append = false) { * @param string $text 文本内容 * @return $this */ - public function text($text = '') { + public function text($text = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -840,7 +882,8 @@ public function text($text = '') { * @param string $mediaid 图片媒体ID * @return $this */ - public function image($mediaid = '') { + public function image($mediaid = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -857,7 +900,8 @@ public function image($mediaid = '') { * @param string $mediaid 语音媒体ID * @return $this */ - public function voice($mediaid = '') { + public function voice($mediaid = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -876,7 +920,8 @@ public function voice($mediaid = '') { * @param string $description 视频描述 * @return $this */ - public function video($mediaid = '', $title = '', $description = '') { + public function video($mediaid = '', $title = '', $description = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -901,7 +946,8 @@ public function video($mediaid = '', $title = '', $description = '') { * @param string $thumbmediaid 音乐图片缩略图的媒体id(可选) * @return $this */ - public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '') { + public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid = '') + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -926,7 +972,8 @@ public function music($title, $desc, $musicurl, $hgmusicurl = '', $thumbmediaid * @param array $newsData * @return $this */ - public function news($newsData = array()) { + public function news($newsData = array()) + { $msg = array( 'ToUserName' => $this->getRevFrom(), 'FromUserName' => $this->getRevTo(), @@ -945,7 +992,8 @@ public function news($newsData = array()) { * @param bool $return 是否返回信息而不抛出到浏览器(默认:否) * @return bool|string */ - public function reply($msg = array(), $return = false) { + public function reply($msg = array(), $return = false) + { if (empty($msg)) { if (empty($this->_msg)) { //防止不先设置回复内容,直接调用reply方法导致异常 return false; @@ -954,7 +1002,7 @@ public function reply($msg = array(), $return = false) { } $xmldata = Tools::arr2xml($msg); if ($this->encrypt_type == 'aes') { //如果来源消息为加密方式 - !class_exists('Prpcrypt', FALSE) && require __DIR__ . '/Lib/Prpcrypt.php'; + !class_exists('Prpcrypt', false) && require __DIR__ . '/Lib/Prpcrypt.php'; $pc = new Prpcrypt($this->encodingAesKey); // 如果是第三方平台,加密得使用 component_appid $array = $pc->encrypt($xmldata, empty($this->config['component_appid']) ? $this->appid : $this->config['component_appid']); @@ -983,7 +1031,8 @@ public function reply($msg = array(), $return = false) { * @param string $text * @return string */ - private function _auto_text_filter($text) { + private function _auto_text_filter($text) + { if (!$this->_text_filter) { return $text; } diff --git a/Wechat/WechatScript.php b/Wechat/WechatScript.php index e96120c..193a354 100644 --- a/Wechat/WechatScript.php +++ b/Wechat/WechatScript.php @@ -11,7 +11,8 @@ * @author Anyon * @date 2016/06/28 11:24 */ -class WechatScript extends Common { +class WechatScript extends Common +{ /** * JSAPI授权TICKET @@ -24,7 +25,8 @@ class WechatScript extends Common { * @param string $appid * @return bool */ - public function resetJsTicket($appid = '') { + public function resetJsTicket($appid = '') + { $this->jsapi_ticket = ''; $authname = 'wechat_jsapi_ticket_' . empty($appid) ? $this->appid : $appid; Tools::removeCache($authname); @@ -38,7 +40,8 @@ public function resetJsTicket($appid = '') { * @param string $access_token 获取 jsapi_ticket 指定 access_token * @return bool|string */ - public function getJsTicket($appid = '', $jsapi_ticket = '', $access_token = '') { + public function getJsTicket($appid = '', $jsapi_ticket = '', $access_token = '') + { if (empty($access_token)) { if (!$this->access_token && !$this->getAccessToken()) { return false; @@ -88,7 +91,8 @@ public function getJsTicket($appid = '', $jsapi_ticket = '', $access_token = '') * @param string $access_token 获取 jsapi_ticket 指定 access_token * @return array|bool 返回签名字串 */ - public function getJsSign($url, $timestamp = 0, $noncestr = '', $appid = '', $access_token = '') { + public function getJsSign($url, $timestamp = 0, $noncestr = '', $appid = '', $access_token = '') + { if (!$this->jsapi_ticket && !$this->getJsTicket($appid, '', $access_token) || empty($url)) { return false; } diff --git a/Wechat/WechatService.php b/Wechat/WechatService.php index 9763fc3..a1b3084 100644 --- a/Wechat/WechatService.php +++ b/Wechat/WechatService.php @@ -12,7 +12,8 @@ * @author Anyon * @date 2016/10/18 00:35:55 */ -class WechatService { +class WechatService +{ const URL_PREFIX = 'https://api.weixin.qq.com/cgi-bin/component'; // 获取服务access_token @@ -57,7 +58,8 @@ class WechatService { * WechatService constructor. * @param array $options */ - public function __construct($options = array()) { + public function __construct($options = array()) + { $options = Loader::config($options); $this->component_encodingaeskey = !empty($options['component_encodingaeskey']) ? $options['component_encodingaeskey'] : ''; $this->component_verify_ticket = !empty($options['component_verify_ticket']) ? $options['component_verify_ticket'] : ''; @@ -70,7 +72,8 @@ public function __construct($options = array()) { * 接收公众平台推送的 Ticket * @return bool|array */ - public function getComonentTicket() { + public function getComonentTicket() + { $receive = new WechatReceive(array( 'appid' => $this->component_appid, 'appsecret' => $this->component_appsecret, @@ -102,7 +105,8 @@ public function getComonentTicket() { * @param string $authorizer_refresh_token 授权方刷新令牌 * @return bool|string */ - public function refreshAccessToken($authorizer_appid, $authorizer_refresh_token) { + public function refreshAccessToken($authorizer_appid, $authorizer_refresh_token) + { empty($this->component_access_token) && $this->getComponentAccessToken(); if (empty($this->component_access_token)) { return false; @@ -123,7 +127,8 @@ public function refreshAccessToken($authorizer_appid, $authorizer_refresh_token) * 获取或刷新服务 AccessToken * @return bool|string */ - public function getComponentAccessToken() { + public function getComponentAccessToken() + { $cacheKey = 'wechat_component_access_token'; $this->component_access_token = Tools::getCache($cacheKey); if (empty($this->component_access_token)) { @@ -148,7 +153,8 @@ public function getComponentAccessToken() { * @param string|null $field * @return bool|array */ - private function _decode($result, $field = null) { + private function _decode($result, $field = null) + { $this->data = json_decode($result, true); if (!empty($this->data['errcode'])) { $this->errCode = $this->data['errcode']; @@ -171,7 +177,8 @@ private function _decode($result, $field = null) { * @param string $authorization_code * @return bool|array */ - public function getAuthorizationInfo($authorization_code) { + public function getAuthorizationInfo($authorization_code) + { empty($this->component_access_token) && $this->getComponentAccessToken(); if (empty($this->component_access_token)) { return false; @@ -195,11 +202,12 @@ public function getAuthorizationInfo($authorization_code) { * @param array $func_info * @return string */ - private function _parseFuncInfo($func_info) { + private function _parseFuncInfo($func_info) + { $authorization_list = array(); foreach ($func_info as $func) { foreach ($func as $f) { - isset($f['id']) && $authorization_list[] = $f['id']; + isset($f['id']) && $authorization_list[] = $f['id']; } } return join($authorization_list, ','); @@ -210,7 +218,8 @@ private function _parseFuncInfo($func_info) { * @param string $authorizer_appid * @return bool */ - public function getWechatInfo($authorizer_appid) { + public function getWechatInfo($authorizer_appid) + { empty($this->component_access_token) && $this->getComponentAccessToken(); $data = array(); $data['component_access_token'] = $this->component_access_token; @@ -237,7 +246,8 @@ public function getWechatInfo($authorizer_appid) { * @param string $option_name * @return bool */ - public function getAuthorizerOption($authorizer_appid, $option_name) { + public function getAuthorizerOption($authorizer_appid, $option_name) + { empty($this->component_access_token) && $this->getComponentAccessToken(); if (empty($this->authorizer_appid)) { return false; @@ -261,7 +271,8 @@ public function getAuthorizerOption($authorizer_appid, $option_name) { * @param string $option_value * @return bool */ - public function setAuthorizerOption($authorizer_appid, $option_name, $option_value) { + public function setAuthorizerOption($authorizer_appid, $option_name, $option_value) + { empty($this->component_access_token) && $this->getComponentAccessToken(); if (empty($this->authorizer_appid)) { return false; @@ -284,7 +295,8 @@ public function setAuthorizerOption($authorizer_appid, $option_name, $option_val * @param string $redirect_uri * @return bool */ - public function getAuthRedirect($redirect_uri) { + public function getAuthRedirect($redirect_uri) + { empty($this->pre_auth_code) && $this->getPreauthCode(); if (empty($this->pre_auth_code)) { return false; @@ -297,7 +309,8 @@ public function getAuthRedirect($redirect_uri) { * * @return bool|string */ - public function getPreauthCode() { + public function getPreauthCode() + { empty($this->component_access_token) && $this->getComponentAccessToken(); if (empty($this->component_access_token)) { return false; @@ -320,7 +333,8 @@ public function getPreauthCode() { * @param string $scope snsapi_userinfo|snsapi_base * @return string */ - public function getOauthRedirect($appid, $redirect_uri, $scope = 'snsapi_userinfo') { + public function getOauthRedirect($appid, $redirect_uri, $scope = 'snsapi_userinfo') + { return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$appid}&redirect_uri=" . urlencode($redirect_uri) . "&response_type=code&scope={$scope}&state={$appid}&component_appid={$this->component_appid}#wechat_redirect"; } @@ -330,7 +344,8 @@ public function getOauthRedirect($appid, $redirect_uri, $scope = 'snsapi_userinf * @param string $appid * @return bool|array */ - public function getOauthAccessToken($appid) { + public function getOauthAccessToken($appid) + { $code = isset($_GET['code']) ? $_GET['code'] : ''; if (empty($code)) { return false; @@ -356,7 +371,8 @@ public function getOauthAccessToken($appid) { * @param string $result * @return bool */ - private function parseJson($result) { + private function parseJson($result) + { $json = json_decode($result, true); if (!empty($json['errcode'])) { $this->errCode = $json['errcode']; @@ -373,7 +389,8 @@ private function parseJson($result) { * @return bool|array {subscribe,openid,nickname,sex,city,province,country,language,headimgurl,subscribe_time,[unionid]} * 注意:unionid字段 只有在用户将公众号绑定到公众号第三方平台账号后,才会出现。建议调用前用isset()检测一下 */ - public function getOauthUserInfo($openid, $oauthAccessToken) { + public function getOauthUserInfo($openid, $oauthAccessToken) + { $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$oauthAccessToken}&openid={$openid}&lang=zh_CN"; return $this->parseJson(Tools::httpGet($url)); } diff --git a/Wechat/WechatUser.php b/Wechat/WechatUser.php index 71a703d..cedec8b 100644 --- a/Wechat/WechatUser.php +++ b/Wechat/WechatUser.php @@ -11,7 +11,8 @@ * @author Anyon * @date 2016/06/28 11:20 */ -class WechatUser extends Common { +class WechatUser extends Common +{ /** 获取粉丝列表 */ const USER_GET_URL = '/user/get?'; @@ -66,7 +67,8 @@ class WechatUser extends Common { * @param string $next_openid * @return bool|array */ - public function getUserList($next_openid = '') { + public function getUserList($next_openid = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -89,7 +91,8 @@ public function getUserList($next_openid = '') { * @return bool|array {subscribe,openid,nickname,sex,city,province,country,language,headimgurl,subscribe_time,[unionid]} * @注意:unionid字段 只有在粉丝将公众号绑定到微信开放平台账号后,才会出现。建议调用前用isset()检测一下 */ - public function getUserInfo($openid) { + public function getUserInfo($openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -112,7 +115,8 @@ public function getUserInfo($openid) { * @param string $lang 指定返回语言 * @return bool|mixed */ - public function getUserBatchInfo(array $openids, $lang = 'zh_CN') { + public function getUserBatchInfo(array $openids, $lang = 'zh_CN') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -139,7 +143,8 @@ public function getUserBatchInfo(array $openids, $lang = 'zh_CN') { * @param string $remark 备注名 * @return bool|array */ - public function updateUserRemark($openid, $remark) { + public function updateUserRemark($openid, $remark) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -161,7 +166,8 @@ public function updateUserRemark($openid, $remark) { * 获取粉丝分组列表 * @return bool|array */ - public function getGroup() { + public function getGroup() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -183,7 +189,8 @@ public function getGroup() { * @param type $id * @return bool */ - public function delGroup($id) { + public function delGroup($id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -206,7 +213,8 @@ public function delGroup($id) { * @param string $openid * @return bool|int 成功则返回粉丝分组id */ - public function getUserGroup($openid) { + public function getUserGroup($openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -230,7 +238,8 @@ public function getUserGroup($openid) { * @param string $name 分组名称 * @return bool|array */ - public function createGroup($name) { + public function createGroup($name) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -254,7 +263,8 @@ public function createGroup($name) { * @param string $name 分组名称 * @return bool|array */ - public function updateGroup($groupid, $name) { + public function updateGroup($groupid, $name) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -278,7 +288,8 @@ public function updateGroup($groupid, $name) { * @param string $openid 粉丝openid * @return bool|array */ - public function updateGroupMembers($groupid, $openid) { + public function updateGroupMembers($groupid, $openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -302,7 +313,8 @@ public function updateGroupMembers($groupid, $openid) { * @param string $openid_list 粉丝openid数组(一次不能超过50个) * @return bool|array */ - public function batchUpdateGroupMembers($groupid, $openid_list) { + public function batchUpdateGroupMembers($groupid, $openid_list) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -325,7 +337,8 @@ public function batchUpdateGroupMembers($groupid, $openid_list) { * @param string $name 标签名称 * @return bool|array */ - public function createTags($name) { + public function createTags($name) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -349,7 +362,8 @@ public function createTags($name) { * @param string $name 标签名称 * @return bool|array */ - public function updateTag($id, $name) { + public function updateTag($id, $name) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -371,7 +385,8 @@ public function updateTag($id, $name) { * 获取粉丝标签列表 * @return bool|array */ - public function getTags() { + public function getTags() + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -393,7 +408,8 @@ public function getTags() { * @param string $id * @return bool */ - public function delTag($id) { + public function delTag($id) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -417,7 +433,8 @@ public function delTag($id) { * @param string $next_openid * @return bool */ - public function getTagUsers($tagid, $next_openid = '') { + public function getTagUsers($tagid, $next_openid = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -441,7 +458,8 @@ public function getTagUsers($tagid, $next_openid = '') { * @param array $openid_list 粉丝openid数组,一次不能超过50个 * @return bool|array */ - public function batchAddUserTag($tagid, $openid_list) { + public function batchAddUserTag($tagid, $openid_list) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -465,7 +483,8 @@ public function batchAddUserTag($tagid, $openid_list) { * @param array $openid_list 粉丝openid数组,一次不能超过50个 * @return bool|array */ - public function batchDeleteUserTag($tagid, $openid_list) { + public function batchDeleteUserTag($tagid, $openid_list) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -488,7 +507,8 @@ public function batchDeleteUserTag($tagid, $openid_list) { * @param string $openid 粉丝openid * @return bool|array */ - public function getUserTags($openid) { + public function getUserTags($openid) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -511,7 +531,8 @@ public function getUserTags($openid) { * @param string $begin_openid * @return bool|array */ - public function getBacklist($begin_openid = '') { + public function getBacklist($begin_openid = '') + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -534,7 +555,8 @@ public function getBacklist($begin_openid = '') { * @param string $openids * @return bool|array */ - public function addBacklist($openids) { + public function addBacklist($openids) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } @@ -557,7 +579,8 @@ public function addBacklist($openids) { * @param string $openids * @return bool|array */ - public function delBacklist($openids) { + public function delBacklist($openids) + { if (!$this->access_token && !$this->getAccessToken()) { return false; } diff --git a/test.php b/test.php index 355003b..2e9a00d 100644 --- a/test.php +++ b/test.php @@ -23,7 +23,7 @@ // 第三方平台 JSSDK 签名包 -$wechat = Db::table('wechat_config')->where('authorizer_appid', 'wx60a43dd8161666d4')->find(); +$wechat = Db::name('WechatConfig')->where('authorizer_appid', 'wx60a43dd8161666d4')->find(); // 第三方授权获取到的 Access_token $access_token = $wechat['authorizer_access_token']; // 参与授权的公众号 APPID