微信分享页面


appid;

      $secret = $this->appserver;

      $_title = '微信';

      $accesstoken = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."");//获取access_token

      $token = json_decode($accesstoken); //对JSON格式的字符串进行编码

      $t = get_object_vars($token);//转换成数组

      $access_token = $t['access_token'];//输出access_token

      $jsapi = file_get_contents("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=".$access_token."&type=jsapi");

      $jsapi = json_decode($jsapi);

      $j = get_object_vars($jsapi);

      $jsapi = $j['ticket'];//get JSAPI

      $time = time();

      $noncestr= $this->createNonceStr();

      $jsapi_ticket= $jsapi;

      $timestamp=$time;

      $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";

      $url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

      $and = "jsapi_ticket=".$jsapi_ticket."&noncestr=".$noncestr."×tamp=".$timestamp."&url=".$url."";

      $signature = sha1($and);

      $data =  ['sign'=>$signature,'time'=>$time,'noncestr'=>$noncestr, 'appId' => $appid];

      return json_encode($data);

  }

  private function createNonceStr($length = 16) {

      $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

      $str = "";

      for ($i = 0; $i < $length; $i++) {

          $str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);

      }

      return $str;

  }

$app=new App();

$foo = $app->jssdk();

$data = json_decode($foo);

?>



你可能感兴趣的:(微信分享页面)