Example #1
0
<?php

// WP_Wechat Handle
$wechat = new WP_Wechat();
// wechat-php-sdk Handle
$we = new Wechat(array('appsecret' => $wechat->app_secret, 'appid' => $wechat->app_id));
$auth = $we->checkAuth();
$js_ticket = $we->getJsTicket();
if (!$js_ticket) {
    $errcode = $we->errCode;
    $errtext = ErrCode::getErrText($weObj->errCode);
    echo "获取 js_ticket 失败! 错误码:{$errcode} 错误原因:{$errtext} ";
}
$https = isset($_SERVER['HTTPS']) && 'on' === $_SERVER['HTTPS'];
$url = ($https ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$js_sign = $we->getJsSign($url);
?>

<script>
    if(window.wx) {
        wx.config({
            debug: /debug=1/.test(location.href),
            appId: '<?php 
echo $js_sign['appId'];
?>
', // 必填,公众号的唯一标识
            timestamp: <?php 
echo $js_sign['timestamp'];
?>
, // 必填,生成签名的时间戳,切记时间戳是整数型,别加引号
            nonceStr: '<?php 
Example #2
0
<?php

include "wechat.class.php";
include 'errCode.php';
$opt = array('appsecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'appid' => 'wxxxxxxxxxxxxxx');
$we = new Wechat($opt);
$auth = $we->checkAuth();
$js_ticket = $we->getJsTicket();
if (!$js_ticket) {
    echo "获取js_ticket失败!<br>";
    echo '错误码:' . $we->errCode;
    echo ' 错误原因:' . ErrCode::getErrText($weObj->errCode);
    exit;
}
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$js_sign = $we->getJsSign($url);
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS-SDK测试页</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
  <link rel="stylesheet" href="style.css?ts=1420775603">
</head>
<body ontouchstart="">
<div class="wxapi_container">
    <div class="wxapi_index_container">
      <ul class="label_box lbox_close wxapi_index_list">
        <li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-basic">基础接口</a></li>
        <li class="label_item wxapi_index_item"><a class="label_inner" href="#menu-share">分享接口</a></li>