Gaoming13\WechatPhpSdk\Utils\Error::code PHP Method

code() public static method

获取某个错误的对象数组
public static code ( $code ) : object(err,
return object(err,
    public static function code($code)
    {
        // 本SDK自定义错误类型
        $code_arr = array('ERR_GET' => array(13001, 'http get api error.'), 'ERR_POST' => array(13002, 'http post api error.'), 'ERR_MEG_TYPE' => array(13003, 'message type is not defined.'));
        return array((object) array('errcode' => $code_arr[$code][0], 'errmsg' => $code_arr[$code][1]), NULL);
    }

Usage Example

コード例 #1
0
 /**
  * 长链接转短链接接口
  *
  * @string $long_url 需要转换的长链接,支持http://、https://、weixin://wxpay 格式的url
  *
  * @return array(err, data)
  * - `err`, 调用失败时得到的异常
  * - `res`, 调用正常时得到的对象
  *
  * Examples:
  * ```
  * list($err, $data) = $api->shorturl('http://me.diary8.com/category/web-front-end.html');
  * echo $data->short_url;
  * ```
  * Result:
  * ```
  * http://w.url.cn/s/ABJrkxE
  * ```
  */
 public function shorturl($long_url)
 {
     $url = self::API_DOMAIN . 'cgi-bin/shorturl?access_token=' . $this->get_access_token();
     $xml = '{"action":"long2short","long_url":"' . $long_url . '"}';
     $res = HttpCurl::post($url, $xml, 'json');
     // 异常处理: 获取时网络错误
     if ($res === FALSE) {
         return Error::code('ERR_GET');
     }
     // 判断是否调用成功
     if ($res->errcode == 0) {
         return array(NULL, $res);
     } else {
         return array($res, NULL);
     }
 }
All Usage Examples Of Gaoming13\WechatPhpSdk\Utils\Error::code
Error