Exemple #1
0
 function jsonDecode($response, $assoc = true)
 {
     $response = preg_replace('/[^\\x20-\\xff]*/', "", $response);
     //清除不可见字符
     $jsonArr = json_decode($response, $assoc);
     if (!is_array($jsonArr)) {
         throw new Core_Api_Exception(Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_RESPONSE_ERROR));
     }
     $ret = $jsonArr["ret"];
     $msg = $jsonArr["msg"];
     $errcode = $jsonArr["errcode"];
     /**
      *Ret=0 成功返回
      *Ret=1 参数错误//todu errcode不够精细
      *Ret=2 频率受限
      *Ret=3 鉴权失败
      *Ret=4 服务器内部错误
      */
     switch ($ret) {
         case 0:
             return $jsonArr;
             break;
         case 1:
             $errcode += 1000;
             if (1001 == $errcode) {
                 $msg = Core_Comm_Apiret::getMsg($errcode);
             } else {
                 empty($msg) && ($msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_ARG_ERR));
             }
             throw new Core_Api_Exception($msg, $errcode);
             break;
         case 2:
             $errcode += 2000;
             if (2001 == $errcode) {
                 $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_AUTH_IPLIMIT);
             } else {
                 if (2002 <= $errcode && $errcode <= 2006) {
                     $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_AUTH_FREQUENCYLIMIT);
                 } else {
                     $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_FREQ_LIMIT);
                 }
             }
             throw new Core_Api_Exception($msg, $errcode);
             break;
         case 3:
             //$errcode = ($errcode >= 12 && $errcode <=15 || $errcode<0) ? 8 : $errcode;
             $errcode = 3000 + $errcode;
             if ($errcode == 3001 || $errcode == 3003) {
                 //无效token或token被吊销
                 $userModel = new Model_User_Member();
                 $ui = array('uid' => $cUser['uid'], 'oauthtoken' => '', 'oauthtokensecret' => '', 'name' => '');
                 $userModel->editUserInfo($ui);
                 $userModel->onSetCurrentAccessToken(null, null, null);
                 $backUrlPrefix = Core_Controller_Front::getInstance()->getModelName() == 'wap' ? 'wap/' : '';
                 Core_Fun::showmsg('', $backUrlPrefix . 'login/r/msg/' . Core_Comm_Modret::RET_ACCOUNT_INVALID, 0, false);
             } elseif (in_array($errcode, array(3004, 3008))) {
                 $msg = Core_Comm_Apiret::getMsg($errcode);
                 throw new Core_Api_Exception($msg, $errcode);
             } else {
                 $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_AUTH_FAIL);
                 throw new Core_Api_Exception($msg, $errcode);
             }
             break;
         case 4:
             // $errcode = (!in_array($errcode,array(0,4,5,6,8,9,10,11,12,13,109)) || $errcode<0) ? -1 : $errcode;//不在指定列表里的errorcode 为非预期错误 默认-1
             if ($errcode == 0) {
                 return $jsonArr;
             } elseif (in_array($errcode, array(0, 4, 5, 6, 8, 9, 10, 11, 12, 13, 109))) {
                 $errcode = 4000 + $errcode;
                 $msg = Core_Comm_Apiret::getMsg($errcode);
                 throw new Core_Api_Exception($msg, $errcode);
             } else {
                 $errcode = 4000 + $errcode;
                 $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_SERVICE_ERROR);
                 throw new Core_Api_Exception($msg, $errcode);
             }
             break;
         case 7:
             //实名验证错误捕捉
             $errcode = 7000 + $errcode;
             $msg = '相关用户未通过实名验证';
             throw new Core_Api_Exception($msg, $errcode);
             break;
         default:
             $msg = Core_Comm_Apiret::getMsg(Core_Comm_Apiret::RET_SERVER_ERROR);
             throw new Core_Api_Exception($msg, Core_Comm_Apiret::RET_SERVER_ERROR);
             break;
     }
 }
Exemple #2
0
 /**
  * 微信错误码函数定义
  *
  * 约定0为成功
  * 小于0代表系统错误(可重试的错误)
  * 大于0为逻辑错误(通常为程序的bug引起,需要人工干预)详细的错误码待定
  *
  * @param int $errorCode 错误码
  * @param string $errorMessage 错误信息
  * @param array $data 返回数据[当$errorCode状态为成功时,才有值]
  * @return string 返回Json错误信息
  */
 public static function returnWeiXinErrorJson($errorCode, $errorMessage = '', $data = null)
 {
     return Core_Comm_Apiret::getRetJson($errorCode, $errorMessage, $data);
 }