/** * 获取jsdk的参数 * @author yf */ public function get_jsdk() { // $access_token = $this->getAccessToken(); // $sql = "SELECT op_value FROM ".$this->table('options')." WHERE op_key='appid' OR op_key='appsecret' OR op_key='jsapi_ticket' OR op_key='jsapi_time'"; // $temp = $this->getCol($sql); // $app['appid'] = $temp[0]; // $app['appsecret'] = $temp[1]; // $wx_token['jsapi_ticket'] = $temp[2]; // $wx_token['jsapi_time'] = $temp[3]; // if($wx_token['jsapi_ticket'] == '' || $_SERVER['REQUEST_TIME'] > $wx_token['jsapi_time'])//7200 // { // $new_info = Ctrl("weixin")->getJsapiTicket($access_token); // if(empty($new_info['ticket'])) // { // $sql = "UPDATE ".$this->table('options')." SET op_value='' WHERE op_key='access_token'"; // $this->query($sql); // unset($new_info); // $access_token = $this->getAccessToken(); // $new_info = Ctrl("weixin")->getJsapiTicket($access_token); // } // $sql = "UPDATE ".$this->table('options')." SET op_value='".$new_info['ticket']."' WHERE op_key='jsapi_ticket'"; // $res = $this->db->query($sql); // $time = $_SERVER['REQUEST_TIME']+$new_info['expires_in']-800; // $sql = "UPDATE ".$this->table('options')." SET op_value='".$time."' WHERE op_key='jsapi_time'"; // $res2 = $this->db->query($sql); // $jsapi_ticket = $new_info['ticket']; // } // else // { // $jsapi_ticket = $wx_token['jsapi_ticket']; // } $sql = "SELECT op_value FROM " . $this->table('options') . " WHERE op_key='appid'"; $appid = $this->getOne($sql); $path = ROOT_PATH . "/Qiaqia/Json/jsapi_ticket.json"; $data = json_decode(file_get_contents($path), true); if (empty($data['jsapi_ticket']) || $data['expire_time'] < yf_time()) { $access_token = $this->getAccessToken(); $new_info = Ctrl("weixin")->getJsapiTicket($access_token); $info['jsapi_ticket'] = $new_info['ticket']; $info['expire_time'] = yf_time() + 7000; $fp = fopen($path, "w"); fwrite($fp, json_encode($info)); fclose($fp); $jsapi_ticket = $new_info['ticket']; } else { $jsapi_ticket = $data['jsapi_ticket']; } $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $timestamp = yf_time(); $nonceStr = $this->createNonceStr(); // 这里参数的顺序要按照 key 值 ASCII 码升序排序 $string = "jsapi_ticket={$jsapi_ticket}&noncestr={$nonceStr}×tamp={$timestamp}&url={$url}"; $signature = sha1($string); $signPackage = array("appId" => $appid, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string); return $signPackage; }
/** * 获取jsdk的参数 * @author yf */ public function get_jsdk() { $appid = $this->weixin_config('appid'); $path = ROOT_PATH . "/Qiaqia/Json/jsapi_ticket.json"; $data = json_decode(file_get_contents($path), true); if (empty($data['jsapi_ticket']) || $data['expire_time'] < yf_time()) { $access_token = $this->getAccessToken(); $new_info = Ctrl("weixin")->getJsapiTicket($access_token); $info['jsapi_ticket'] = $new_info['ticket']; $info['expire_time'] = yf_time() + 7000; $fp = fopen($path, "w"); fwrite($fp, json_encode($info)); fclose($fp); $jsapi_ticket = $new_info['ticket']; } else { $jsapi_ticket = $data['jsapi_ticket']; } $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://"; $url = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; $timestamp = yf_time(); $nonceStr = $this->createNonceStr(); // 这里参数的顺序要按照 key 值 ASCII 码升序排序 $string = "jsapi_ticket={$jsapi_ticket}&noncestr={$nonceStr}×tamp={$timestamp}&url={$url}"; $signature = sha1($string); $signPackage = array("appId" => $appid, "nonceStr" => $nonceStr, "timestamp" => $timestamp, "url" => $url, "signature" => $signature, "rawString" => $string); return $signPackage; }