public function getServiceConfig() { return array('factories' => array('User\\Model\\QQ' => function ($sm) { $config = $sm->get('config'); $user = new QQ($config['platform'][QQ::ePlatform_QQ]['appid'], $config['platform'][QQ::ePlatform_QQ]['appkey']); $user->setServiceLocator($sm); return $user; }, 'User\\Model\\WX' => function ($sm) { $config = $sm->get('config'); $user = new WX($config['platform'][WX::ePlatform_Weixin]['appid'], $config['platform'][WX::ePlatform_Weixin]['appkey']); $user->setServiceLocator($sm); return $user; })); }
/** * 游客模式签权(WX) * @param array 通过HTTP RAW POST方式提交数据,数据字段定义如下: * platform Integer (required)腾讯平台定义。定义如下:1.微信,2.QQ,3.WT。4.QQ大厅。5.游客模式,此处只能为5 * os Integer (required)客户端操作系统定义。0: iOS, 1: Android * open_id String (required)用户openID * access_token String (required)用户访问接口的access_token * @return array 返回一个JSON数组,结构如下: * ret Integer 成功or失败。0失败,1成功 * msg String 返回消息 * data Mixed 返回数据,如果成功,返回格式如下: * user_name String 显示为Guest * user_id String 用户OpenID * time Integer 当前时间戳 * flag String 该数据包的签名 */ public function guestAuthAction() { $logger = $this->getServiceLocator()->get('Zend\\Log'); $config = $this->getServiceLocator()->get('config'); $user = $this->getServiceLocator()->get('User\\Model\\WX'); $data = json_decode($this->request->getContent(), true); $logger->info('Data from client(post):'); $logger->debug($data); if (($ret = $user->store($data)) === true) { $result = $user->guestCheckToken($data); if ($result['ret'] === WX::CX_CODE_SUCCESS) { $r_data = $result['data']; if ($r_data['ret'] === WX::TX_CODE_SUCCESS) { $rdata = $user->signCxResponse(array('user_name' => 'Guest', 'user_id' => $user->openid)); $response = WX::formatResponse(WX::CX_CODE_SUCCESS, 'success', $rdata); } else { //MSDK Return result error $response = WX::formatResponse(WX::CX_CODE_FAILED, 'MSDK return error!', $r_data); } } else { //MSDK Http response error $response = WX::formatResponse($result); } } else { //Data validation failed $response = WX::formatResponse(WX::CX_CODE_FAILED, 'Data posted from client is invalid!', $ret); } //output //return new JsonModel($response); echo json_encode($response); exit; }