Exemple #1
0
 /**
  * save token to db
  */
 public static function initWxTokenToDB()
 {
     global $db;
     $url = wxTokenUrl() . "&appid=" . appid() . "&secret=" . secret();
     // 请求微信token
     //LogUtil::logs("initWxTokenToDB tokenurl====>".$url, getLogFile('/business.log'));
     $arr = RequestUtil::httpGet($url);
     $newToken = $arr['access_token'];
     //LogUtil::logs("initWxTokenToDB newToken====>".$newToken, getLogFile('/business.log'));
     // 请求微信ticket
     $newTicket = self::initTicket($newToken);
     $updatetime = DateUtil::getCurrentTime();
     // 加锁文件
     if (file_exists($lockfile)) {
         //LogUtil::logs("initWxTokenToDB ====> file in writing, only can read\r\n", getLogFile('/business.log'));
         exit;
     }
     // save or update;
     $db->exec("INSERT INTO wx_token(id, token, updatetime, ticket) \r\n\t\tvalues(1, '{$newToken}','{$updatetime}','{$newTicket}') \r\n\t\tON DUPLICATE KEY UPDATE token='{$newToken}', updatetime='{$updatetime}', ticket='{$newTicket}'");
     // 关闭锁文件
     fclose($lockTemp);
     // 删除锁文件
     unlink($lockfile);
     return $newToken;
 }
Exemple #2
0
<?php

require_once '../../weixin/RequestUtil.php';
require_once '../../weixin/DateUtil.php';
require_once '../../weixin/globleconfig.php';
require_once '../../weixin/LogUtil.php';
require_once '../configs/smarty.inc.php';
// http://www.jb51.net/article/48019.htm
if (isset($_GET["code"])) {
    $code = $_GET["code"];
    $secret = secret();
    $appid = appid();
    $oauthurl = wxOauth();
    $url = $oauthurl . "?appid=" . $appid . "&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
    //LogUtil::logs($url, getLogFile("/business.log"));
    $returnJson = RequestUtil::httpGet($url);
    // {"access_token":"OezXcEiiBSKSxW0eoylIeG_LpV4TpnX-BxNbAVVAasaRyPm55zyI9CKaVNciQOEw8iu_pEDXCiBKbbSJbzzqarhyfecqXoplnmCl7HsBiWFARy1Ob3MealEkubEDs8KHeRbAr5Awrvr7RR3i5t24GA","expires_in":7200,"refresh_token":"OezXcEiiBSKSxW0eoylIeG_LpV4TpnX-BxNbAVVAasaRyPm55zyI9CKaVNciQOEwUHOmtG9PkoiFUefqTDaX00sVqxhfoyE-jbYDCIjldLBnZvj1QP0gGev-Tw2BWQWTdIOnZ9EQDB0Oi0w2ZlT0lA","openid":"osp6swrNZiWtEuTy-Gj1cBVA1l38","scope":"snsapi_base"}
    $openid = $returnJson["openid"];
    if (!empty($returnJson["openid"])) {
        $smarty->assign('openid', $openid);
        $smarty->display('chatingroom/chating.html');
    }
}