當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Wechat::getJsSign方法代碼示例

本文整理匯總了PHP中Wechat::getJsSign方法的典型用法代碼示例。如果您正苦於以下問題:PHP Wechat::getJsSign方法的具體用法?PHP Wechat::getJsSign怎麽用?PHP Wechat::getJsSign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Wechat的用法示例。


在下文中一共展示了Wechat::getJsSign方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getJsSign

 function getJsSign()
 {
     if ($this->request->is('post')) {
         $url = $this->request->data('url');
         $timestamp = $this->request->data('timestamp');
         $nonceStr = $this->request->data('nonceStr');
         $appId = 'yourappid';
         $wxObj = new Wechat(array('token' => 'yourtoken', 'appid' => $appId, 'appsecret' => 'yourpants'));
         //調用對應的函數
         $sign = $wxObj->getJsSign($url, $timestamp, $nonceStr);
         //如果token失效,清除token重試一次
         if ($wxObj->errCode == 40001 || $wxObj->errCode == 42001) {
             $wxObj->resetAuth();
             $sign = $wxObj->getJsSign();
         }
         //如果返回false,獲取errcode和errmsg
         if (!$sign) {
             return $this->sentJson(array('errCode' => $wxObj->errCode, 'errMsg' => WechatErrCode::getErrText($wxObj->errCode)));
         }
         $package = array('signature' => $sign, 'nonceStr' => $nonceStr, 'appId' => $appId, 'timestamp' => $timestamp);
         return $this->sentJson(array('errCode' => 0, 'errMsg' => '', 'result' => $package));
     }
 }
開發者ID:kunyan,項目名稱:wechat-cakephp-sdk,代碼行數:23,代碼來源:ApiContorller.php

示例2: showTip

function showTip($smarty, $tip, $db, $title)
{
    $options = array('token' => WX_TOKEN, 'appid' => WX_APPID, 'encodingaeskey' => '6pnP7qHyqJ1kFXMjuO4Z3QrpOa9WfapsgkPOtXoZKC2', 'appsecret' => WX_SECRET, 'logcallback' => logdebug);
    $we = new Wechat($options);
    $auth = $we->checkAuth();
    $js_ticket = $we->getJsTicket();
    $smarty->assign('tip', $tip);
    $smarty->assign('title', $title);
    $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $smarty->assign('js_sign', $we->getJsSign($url));
    $smarty->display('templates/tip.html');
    $db->disconnect();
    die;
}
開發者ID:xuhongxu96,項目名稱:Tagexing,代碼行數:14,代碼來源:main.php

示例3: Wechat

<?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 
開發者ID:EaseCloud,項目名稱:WP-Wechat,代碼行數:31,代碼來源:header-jssdk.php

示例4: getToken

 function getToken($url)
 {
     //引入微信類庫
     APP::load(APP_FILE . 'common/class/wechat.class.php');
     $weObj = new Wechat(APP::$config['wechat']);
     // 注意 URL 一定要動態獲取,不能 hardcode.
     $protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? "https://" : "http://";
     $uri = "{$protocol}{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
     $signPackage = $weObj->getJsSign($uri);
     if (!isset($_GET['code'])) {
         header("Location: " . $url);
         exit;
     }
     $data = $weObj->getOauthAccessToken();
     if (!$data) {
         header("Location: " . $url);
         exit;
     }
     $userinfo = $weObj->getOauthUserinfo($data['access_token'], $data['openid']);
     $this->assign('signPackage', $signPackage);
     $_SESSION['openid'] = $data['openid'];
 }
開發者ID:eyblog,項目名稱:mvc,代碼行數:22,代碼來源:cpController.class.php

示例5: time

    echo '錯誤碼:'.$we->errCode;

    echo ' 錯誤原因:'.ErrCode::getErrText($weObj->errCode);

    exit;

}

$timestamp = time();

$noncestr = $we->generateNonceStr();

$url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$js_sign = $we->getJsSign($url, $timestamp, $noncestr); //會自己檢測調用checkAuth方法獲取access_token

?>

<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">
開發者ID:xupnge1314,項目名稱:sscpms,代碼行數:29,代碼來源:index.php

示例6: json_encode

<?php

include "../qy-sdk/wechat.class.php";
require 'api_rb.php';
require 'api_db.php';
$url = isset($_REQUEST['url']) ? $_REQUEST['url'] : '';
$timestamp = time();
$noncestr = 'Gds_Wechat_CSC_V2';
// Log
_log(json_encode(['url' => $url, 'timestamp' => $timestamp, 'noncestr' => $noncestr]));
// Check
if (empty($url)) {
    header('Content-type:text/json;charset=utf-8');
    echo json_encode(['result' => 'failed', 'error' => 'missing argument']);
    die;
}
// Get Ticket and Sign
$options = ['token' => 'nizhidaoma', 'encodingaeskey' => 'xc8rRK4iOQjTJK9hOYhRrC9sPBJvF5Jhjq203iMC7vF', 'appid' => 'wxe85832e232e73f41', 'appsecret' => '4c8f1aa381675dd2569fc9482052afdc', 'debug' => true, 'logcallback' => '_log'];
$weObj = new Wechat($options);
$jsTicket = $weObj->getJsTicket();
$jsSign = $weObj->getJsSign($url, $timestamp, $noncestr);
// Return
header('Content-type:text/json;charset=utf-8');
echo json_encode(['result' => 'true', 'sign' => $jsSign]);
die;
開發者ID:adexbn,項目名稱:gds_wechat,代碼行數:25,代碼來源:api_js.php


注:本文中的Wechat::getJsSign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。