<?php include_once "./wxapi/wxapi.php"; $jsApi = new Wxapi(); if (!isset($_GET['code'])) { //触发微信返回code码 $url = $jsApi->createOauthUrlForCode(Wxconfig::JS_API_CALL_URL); Header("Location: {$url}"); } else { //获取code码,以获取openid $code = $_GET['code']; } //获取access_token $tokenurl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" . Wxconfig::APPID . "&secret=" . Wxconfig::APPSECRET . "&code=" . $code . "&grant_type=authorization_code"; $res = $jsApi->http_request($tokenurl); if ($res) { $tk = json_decode($res); if ($tk->access_token != "") { $accesstoken = $tk->access_token; } else { echo "get access token empty"; exit(0); } } else { echo "get access token error"; exit(0); } //调起地址控件签名 $timestamp = time(); $noncestr = $jsApi->createNoncestr(); $url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
public function __construct() { parent::__construct(); }