微信js的引用

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&timestamp=$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;
    }

 

微信js的引用

上一篇:微信支付----维权接口开发!(转掌眼)


下一篇:微信开发第二篇:工具篇