public function process() { //只处理文本消息和自定义菜单消息 if (!($this->_msgType != 'text' || $this->_msgType == 'event')) { interface_log(DEBUG, 0, "msgType:" . $this->_msgType); return $this->makeHint("你发的不是文字或菜单消息"); } try { $STO = new SingleTableOperation("userinput", "ES"); if ($this->_msgType == 'event' && $this->_event == 'CLICK') { $mode = $this->_eventKey; //更新用户mode $ret = $STO->getObject(array("userId" => $this->_fromUserName)); if (!empty($ret)) { $STO->updataObject(array('mode' => $mode), array("userId" => $this->_fromUserName)); } else { $STO->addObject(array("userId" => $this->_fromUserName, 'mode' => $mode)); } return $this->makeHint("模式设置成:" . $mode); } else { $text = $this->_content; $ret = $STO->getObject(array("userId" => $this->_fromUserName)); if (empty($ret)) { $STO->addObject(array("userId" => $this->_fromUserName)); return $this->makeHint($text); } else { $mode = $ret[0]['mode']; $STO->updataObject(array('input' => $ret[0]['input']), array("userId" => $this->_fromUserName)); return $this->makeHint($text); } } } catch (DB_Exception $e) { interface_log(ERROR, EC_DB_OP_EXCEPTION, "query db error" . $e->getMessage()); } }
public static function getToken($force = false) { try { $STO = new SingleTableOperation(); $STO->setTableName("ctoken"); if ($force == false) { $ret = $STO->getObject(); interface_log(DEBUG, 0, "token data get from ctoken: " . json_encode($ret)); if (count($ret) == 1) { $token = $ret[0]['token']; $expire = $ret[0]['expire']; $addTimestamp = $ret[0]['addTimestamp']; $current = time(); if ($addTimestamp + $expire + 30 < $current) { return $token; } } } $para = array("grant_type" => "client_credential", "appid" => WX_API_APPID, "secret" => WX_API_APPSECRET); $url = WX_API_URL . "token"; interface_log(DEBUG, 0, "url:" . $url . " req data:" . json_encode($para)); $ret = doCurlGetRequest($url, $para); interface_log(DEBUG, 0, "response data:" . $ret); $retData = json_decode($ret, true); if (!$retData || $retData['errcode']) { interface_log(ERROR, EC_OTHER, "requst wx to get token error"); return false; } //从返回数据中获取得到的access_token和它的过期时间,更新ctoken表 $token = $retData['access_token']; $expire = $retData['expires_in']; $STO->delObject(); $STO->addObject(array('token' => $token, "expire" => $expire, "addTimestamp" => time())); return $token; } catch (DB_Exception $e) { interface_log(ERROR, EC_DB_OP_EXCEPTION, "operate ctoken error! msg:" . $e->getMessage()); return false; } }
public function process() { try { $oTableOperate = new SingleTableOperation('cUser', "MYZL"); $data = $oTableOperate->getObject(array('userId' => $this->_args['userId'])); if (count($data)) { $this->_retValue = EC_RECORD_EXIST; $this->_retMsg = "user already exist!"; interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } //添加用户记录,设置相关的字段,这里可以根据自己的策略设置 $oTableOperate->addObject(array('userId' => $this->_args['userId'], 'password' => $this->_args['password'], 'email' => $this->_args['email'], 'money' => 100, 'bulletNum' => 5, 'xsft' => 5, 'hdcx' => 5, 'chxs' => 5, 'sszm' => 5, 'addTimeStamp' => getCurrentTime())); $this->_responseText = MYZL_HINT_ADDUSER_SUC; } catch (DB_Exception $e) { $errorNum = $oTableOperate->getErrorNum(); $this->_retMsg = $oTableOperate->getErrorInfo() . $e->getMessage(); $this->_retValue = genRetCode($errorNum); interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } return true; }
$oTable = new SingleTableOperation('cWaitingUser', 'MYZL'); while (1) { $data = $oTable->getObject(array('_sortExpress' => 'addTimeStamp')); matcher_log(DEBUG, 0, json_encode($data)); if (count($data) < 2) { sleep(2); continue; } else { $length = count($data); for ($i = 0; $i + 1 < $length; $i = $i + 2) { $userId1 = $data[$i]['userId']; if ($i >= $length) { continue; } $userId2 = $data[$i + 1]['userId']; DbFactory::getInstance('MYZL')->autoCommit(); //minus bullets DbFactory::getInstance('MYZL')->update("update cUser set bulletNum=bulletNum-1 where userId IN('" . $userId1 . "', '" . $userId2 . "')"); //删除 $oTable->delObject(array('userId' => array($userId1, $userId2))); //添加 $oTable->addObject(array('_tableName' => 'cFight', 'user1' => $userId1, 'user2' => $userId2, 'first' => $userId1, 'current' => $userId1, 'operation' => START, 'maxMoney' => $maxMoney, 'minMoney' => $minMoney, 'operator' => 0)); matcher_log(DEBUG, 0, "add {$userId1} and {$userId2} to fight"); DbFactory::getInstance('MYZL')->tryCommit(); } } } } catch (DB_Exception $e) { DbFactory::getInstance()->rollback(); matcher_log(ERROR, 0, $oTable->getErrorInfo() . $e->getMessage()); }
public function process() { //return $this->makeHint("系统正在升级!请稍候使用"); try { if ($this->_msgType != 'image') { $contentStr = FF_HINT_TYPE_ERROR; if ($this->_msgType == 'text') { $contents = (string) trim($this->_postObject->Content); if ($contents == 'Hello2BizUser') { $contentStr = FF_HINT_HELLO; } } if ($this->_msgType == 'event') { $event = (string) trim($this->_postObject->Event); if ($event == 'subscribe') { $contentStr = FF_HINT_HELLO; } } return $this->makeHint($contentStr); } $this->_url = trim($this->_postObject->PicUrl); //下载图片到本地 $fileName = $this->downloadPic(); $this->_url = FF_URL_HEADER . $fileName; // 1.检验是否有脸 $ret = faceStub::detect($this->_url); if ($ret === false) { return $this->makeHint(FF_HINT_FACE_ERROR); } if (count($ret['face']) == 0) { return $this->makeHint(FF_HINT_NO_FACE); } if (count($ret['face']) > 1) { return $this->makeHint(FF_HINT_MULTIPLE_FACE); } $faceId = $ret['face'][0]['face_id']; $oTable = new SingleTableOperation(); // 插入face到cFace $oTable->setTableName('cface'); $oTable->addObject(array('faceId' => $faceId, 'personName' => $this->_fromUserName, 'url' => $ret['url'])); // 2.找到最像的脸 $ret = faceStub::search($faceId, GROUP_NAME, 2); if ($ret === false) { return $this->makeHint(FF_HINT_FACE_ERROR); } $candidates = $ret['candidate']; if (count($candidates) == 0) { return $this->makeHint(FF_HINT_FACE_NO_CANDIDATE); } // 查找查询用户,看是否已上传过face $oTable->setTableName('cperson'); $ret = $oTable->getObject(array('personName' => $this->_fromUserName)); if (count($ret)) { $userFaceIds = array(); foreach ($ret as $item) { $userFaceIds[] = $item['faceId']; } $newCandidate = array(); // 从结果集中删除掉用户自己 foreach ($candidates as $item) { if (!in_array($item['face_id'], $userFaceIds)) { $newCandidate[] = $item; } } $candidates = $newCandidate; // 更新用户的faceId $oTable->updateObject(array('faceId' => $faceId), array('personName' => $this->_fromUserName)); // 更新faceplusplus的person:先删除person的face,再加入该faceId $result = faceStub::removeFaceFromPerson($this->_fromUserName, 'all'); if ($result === false) { return $this->makeHint(FF_HINT_FACE_ERROR); } $result = faceStub::addFaceToPerson($this->_fromUserName, $faceId); if ($result === false) { return $this->makeHint(FF_HINT_FACE_ERROR); } } else { // 插入记录到cPerson $oTable->addObject(array('personName' => $this->_fromUserName, 'faceId' => $faceId)); // 请求faceplusplus创建person和,并加到group中 $result = faceStub::createPerson($this->_fromUserName, $faceId, GROUP_NAME); if ($result === false) { return $this->makeHint(FF_HINT_FACE_ERROR); } } if (count($candidates) == 0) { return $this->makeHint(FF_HINT_FACE_NO_CANDIDATE); } // 从数据库中查询face的url $oTable->setTableName('cface'); $ret = $oTable->getObject(array('faceId' => $candidates[0]['face_id'])); if (count($ret) == 0) { return $this->makeHint(FF_HINT_FACE_NO_CANDIDATE); } $url = $ret[0]['url']; $resultStr = sprintf(SUCC_TPL_FINDFACE, $this->_fromUserName, $this->_toUserName, $this->_time, $url, $url); $oTable->setTableName('cstatus'); $ret = $oTable->getObject(array('key' => 'lastTrain')); $lastTrain = $ret[0]['value']; date_default_timezone_set(PRC); $now = date('YmdG'); if ($now != $lastTrain) { faceStub::train(GROUP_NAME, 'search'); $oTable->updateObject(array('value' => $now), array('key' => 'lastTrain')); } return $resultStr; } catch (Exception $e) { interface_log(ERROR, EC_DB_OP_EXCEPTION, $e->getMessage()); return $this->makeHint(FF_HINT_INNER_ERROR); } }