Exemple #1
0
 public static function reqMenu($interface, $data)
 {
     $token = tokenStub::getToken();
     $retry = 3;
     while ($retry) {
         $retry--;
         if (false === $token) {
             interfaceLog(DEBUG, EC_OTHER, "get token error!");
             return false;
         }
         $url = WX_API_URL . "{$interface}?access_token=" . $token;
         $data_js = json_encode($data, JSON_UNESCAPED_UNICODE);
         interfaceLog(DEBUG, 0, "req url:" . $url . " req data:" . $data_js);
         $ret = doCurlPostRequest($url, $data_js);
         interfaceLog(DEBUG, 0, "response:" . $ret);
         $retData = json_decode($ret, true);
         if (!$retData || $retData['errcode']) {
             interfaceLog(DEBUG, EC_OTHER, "req create menu error");
             if ($retData['errcode'] == 40014) {
                 $token = tokenStub::getToken(true);
             }
         } else {
             return $retData;
         }
     }
     return false;
 }
Exemple #2
0
function exitErrorInput()
{
    echo "error input!";
    interfaceLog(INFO, EC_OK, "***** interface request end *****");
    interfaceLog(INFO, EC_OK, "*********************************");
    interfaceLog(INFO, EC_OK, "");
    exit(0);
}
 public function init($postObj)
 {
     if (false === parent::init($postObj)) {
         interfaceLog(ERROR, EC_OTHER, "init fail");
         return false;
     }
     if ($this->_msgType == "text") {
         $this->_content = (string) $postObj->Content;
     } else {
         if ($this->_msgType == 'event') {
             $this->_event = (string) $postObj->Event;
             $this->_eventKey = (string) $postObj->EventKey;
         }
     }
     return true;
 }
Exemple #4
0
 public function init($postObj)
 {
     $this->_postObject = $postObj;
     if ($this->_postObject == false) {
         interfaceLog(ERROR, 0, "begin fail");
         return false;
     }
     $this->_fromUserName = (string) trim($this->_postObject->FromUserName);
     $this->_toUserName = (string) trim($this->_postObject->ToUserName);
     $this->_msgType = (string) trim($this->_postObject->MsgType);
     $this->_createTime = (string) trim($this->_postObjet->CreateTime);
     $this->msgId = (int) trim($this->_postObject->MsgId);
     $this->_time = time();
     if (!($this->_fromUserName && $this->_toUserName && $this->_msgType)) {
         interfaceLog(ERROR, 0, "end fail");
         return false;
     }
     return true;
 }
Exemple #5
0
 public static function getToken($force = false)
 {
     try {
         $STO = new SingleTableOperation();
         if ($force == false) {
             $ret = $STO->getObject(array("appId" => APP_ID));
             interfaceLog(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" => APP_ID, "secret" => APP_SECRET);
         $url = WX_API_URL . "token";
         interfaceLog(DEBUG, 0, "url:" . $url . " req data:" . json_encode($para));
         $ret = doCurlGetRequest($url, $para);
         interfaceLog(DEBUG, 0, "response data:" . $ret);
         $retData = json_decode($ret, true);
         if (!$retData || in_array('errcode', $retData)) {
             interfaceLog(ERROR, EC_OTHER, "request weixin to get token error");
             return false;
         }
         $token = $retData['access_token'];
         $expire = $retData['expires_in'];
         $STO->delObject(array("appid" => APP_ID));
         $STO->addObject(array("appid" => APP_ID, "token" => $token, "expire" => $expire, "addTimestamp" => time()));
         return $token;
     } catch (DB_Exception $e) {
         interfaceLog(ERROR, EC_DB_OP_EXCEPTION, "operate ctoken error!msg:" . $e->getMessage());
         return false;
     }
 }
Exemple #6
0
<?php

require_once dirname(__FILE__) . "/../common/GlobalFunctions.php";
require_once dirname(__FILE__) . "/../common/GlobalDefine.php";
require_once dirname(__FILE__) . "/../class/menuStub.php";
interfaceLog(DEBUG, 0, "***start menu**");
$menuData = array("button" => array(array('type' => 'click', 'name' => '热门歌曲', 'key' => 'V1001_TODAY_MUSIC'), array('type' => 'click', 'name' => '歌手', 'key' => 'V1001_TODAY_SINGER')));
$ret = menuStub::create($menuData);
if (false === $ret) {
    interfaceLog(DEBUG, 0, "create menu fail!");
    echo "create menu fail!\n";
} else {
    interfaceLog(DEBUG, 0, "create menu success");
    echo "create menu success!\n";
}
interfaceLog(DEBUG, 0, "***end menu***");
Exemple #7
0
 public function update($sql)
 {
     interfaceLog(INFO, EC_OK, "SQL[{$sql}]");
     if (!$this->_conn || !$this->ping($this->_conn)) {
         if ($this->_autoCommitTime) {
             throw new DB_Exception('auto commit time is not zero when reconnect to db');
         } else {
             $this->connect();
         }
     }
     $startTime = time();
     $urs = mysqli_query($this->_conn, $sql);
     if (!$urs) {
         throw new DB_Exception('更新失败:' . mysqli_error($this->_conn));
     } else {
         interfaceLog(INFO, EC_OK, "excute time:" . $startTime . "(ms)SQL[{$sql}]");
         return $urs;
     }
 }