Beispiel #1
0
 public function handle_request()
 {
     $apf = APF::get_instance();
     $request = $apf->get_request();
     $response = $apf->get_response();
     try {
         $key = $request->get_parameter('key');
         $hash = $request->get_parameter('hash');
         $brokerId = $request->get_parameter('broker_id');
         if (!($key && $hash && $brokerId)) {
             throw new Exception_ChristmasException('Parameters incomplete.', self::CODE_PARAMETERS_INCOMPLETE);
         }
         $params = $request->get_parameters();
         unset($params['hash']);
         ksort($params);
         // 按照键值排序(升序)所有参数
         $params['secret'] = self::$account['secret'];
         $query = http_build_query($params);
         if (md5($query) !== $hash) {
             throw new Exception_ChristmasException('Parameters invalid.', self::CODE_PARAMETERS_INVALID);
         }
         // 获取经纪人详情
         self::$BrokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId);
         $userId = self::$BrokerInfo['BaseInfo'][strtoupper('userId')];
         // 判断经纪人是否通过双证验证
         if (self::$BrokerInfo['BaseInfo'][strtoupper('checkstate')] == 0) {
             throw new Exception_ChristmasException('Check state first.', self::CODE_NOT_CHECK_STATE);
         }
         // 判断今天是否已经送过锤子
         if (Model_Christmas_HammerLog::hammerLogForApp($brokerId, date('Y-m-d'))) {
             throw new Exception_ChristmasException('Already gifted, today.', self::CODE_ALREADY_GIFTED);
         }
         // 经纪人添加锤子
         Model_Christmas_BrokerHammer::incrBrokerHammerForApp($brokerId);
         // 发送系统消息
         $messages = Util_Christmas::messages();
         if (isset($messages[Model_Christmas_HammerLog::TYPE_APP_PUBLISH_HOUSE])) {
             Bll_Service_Message::sendSystem(array('receiverIds' => $userId, 'message' => $messages[Model_Christmas_HammerLog::TYPE_APP_PUBLISH_HOUSE]));
         }
         $result = array('code' => self::CODE_SUCCESS, 'message' => 'Success.');
     } catch (Exception_ChristmasException $e) {
         $result = array('code' => $e->getCode(), 'message' => $e->getMessage());
     } catch (Exception $e) {
         // 500 Error
         // http_response_code('500');
         $result = array('code' => '500', 'message' => 'Server Error.');
     }
     $response->set_content_type('application/json', 'UTF-8');
     $response->add_header('Cache-Control', 'no-cache, no-store, must-revalidate');
     $response->add_header('Pragma', 'no-cache');
     $response->add_header('Expires', 0);
     echo json_encode($result);
     die;
 }