Пример #1
0
 static function get($function, $seller_config_id, $options = null)
 {
     if ($ptSettingData = self::getPtSettingById($seller_config_id)) {
         switch ($ptSettingData['type']) {
             case self::PT_TYPE_WECHAT:
                 if (!in_array($function, self::$functions)) {
                     return array('errCode' => -1, 'errMsg' => self::ERR_MSG_FUNCTION_NOT_FOUND, 'result' => '');
                 }
                 $wxObj = new Wechat($ptSettingData['settings']);
                 $result = self::run($wxObj, $function, $options);
                 if ($wxObj->errCode == 40001 || $wxObj->errCode == 42001) {
                     $wxObj->resetAuth();
                     $result = self::run($wxObj, $function, $options);
                 }
                 return array('errCode' => $wxObj->errCode, 'result' => $result, 'errMsg' => WechatErrCode::getErrText($wxObj->errCode));
             case self::PT_TYPE_BAIDU:
                 //do nothing
         }
     }
     return array('errCode' => -1, 'errMsg' => self::ERR_MSG_PTSETTING_NOT_FOUND, 'result' => '');
 }
Пример #2
0
 function getJsSign()
 {
     if ($this->request->is('post')) {
         $url = $this->request->data('url');
         $timestamp = $this->request->data('timestamp');
         $nonceStr = $this->request->data('nonceStr');
         $appId = 'yourappid';
         $wxObj = new Wechat(array('token' => 'yourtoken', 'appid' => $appId, 'appsecret' => 'yourpants'));
         //调用对应的函数
         $sign = $wxObj->getJsSign($url, $timestamp, $nonceStr);
         //如果token失效,清除token重试一次
         if ($wxObj->errCode == 40001 || $wxObj->errCode == 42001) {
             $wxObj->resetAuth();
             $sign = $wxObj->getJsSign();
         }
         //如果返回false,获取errcode和errmsg
         if (!$sign) {
             return $this->sentJson(array('errCode' => $wxObj->errCode, 'errMsg' => WechatErrCode::getErrText($wxObj->errCode)));
         }
         $package = array('signature' => $sign, 'nonceStr' => $nonceStr, 'appId' => $appId, 'timestamp' => $timestamp);
         return $this->sentJson(array('errCode' => 0, 'errMsg' => '', 'result' => $package));
     }
 }