来源:自学PHP网 时间:2016-06-08 16:09 作者: 阅读:次
[导读] public function seach_accurate(){ import ( Class Wechat , APP_PATH ); $weObj = new WeChat (array()); $jsapiTicket =...
public function seach_accurate(){ import ( 'Class.Wechat', APP_PATH ); $weObj = new WeChat (array()); $jsapiTicket = $weObj->getJsApiTicket(); $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; $timestamp = time(); $nonceStr = $weObj->generateNonceStr(); // 这里参数的顺序要按照 key 值 ASCII 码升序排序 $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url"; $signature = sha1($string); $signPackage = array( "appId" => C('appid'), "nonceStr" => $nonceStr, "timestamp" => $timestamp, "signature" => $signature, "rawString" => $string ); $this->signPackage=$signPackage; $this->display(); } 以下是获取签名新增的一个函数 /** * 获取 ticket * */ public function getJsApiTicket(){ if (!$this->access_token && !$this->checkAuth()) return false; $appid=$this->appid; $tickname='jsapi_ticket'.$appid; if($rs=S($tickname)){ return $rs; } $result = $this->http_get(self::API_URL_PREFIX.self::TICKET_GET.'access_token='.$this->access_token.'&type=jsapi'); if ($result) { $json = json_decode($result,true); if (!$json || !empty($json['errcode'])) { $this->errCode = $json['errcode']; $this->errMsg = $json['errmsg']; return false; } $expire = $json['expires_in'] ? intval($json['expires_in'])-100 : 3600; S($tickname,$json['ticket'],$expire); return $json['ticket']; } return false; } |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com