상속: extends AbstractClient
예제 #1
0
require './_example.php';
use Thenbsp\Wechat\OAuth\Client;
use Thenbsp\Wechat\Payment\JsBrandWCPayRequest;
session_start();
/**
 * 只能在微信中打开
 */
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false) {
    exit('请在微信中打开');
}
/**
 * getBrandWCPayRequest 方式支付需要获取用户 openid
 */
if (!isset($_SESSION['openid'])) {
    $client = new Client($wechat);
    if (!isset($_GET['code'])) {
        $callback = 'http://----------YOUR CALLBACK URL----------/_example/payment-brandwcpayrequest.php';
        header('Location: ' . $client->getAuthorizeUrl($callback));
    } else {
        $token = $client->getAccessToken($_GET['code']);
        $_SESSION['openid'] = $token['openid'];
    }
}
/**
 * 获取 getBrandWCPayRequest 配置文件
 */
$options = array('body' => 'iphone 6 plus', 'total_fee' => 1, 'out_trade_no' => date('YmdHis') . mt_rand(10000, 99999), 'notify_url' => 'http://----------YOUR NOTIFY URL----------/_example/payment-notify.php', 'openid' => $_SESSION['openid']);
$o = new JsBrandWCPayRequest($wechat, $options);
$configJSON = $o->getConfig();
?>
예제 #2
0
<?php

require './example.php';
session_start();
use Thenbsp\Wechat\OAuth\Client;
use Thenbsp\Wechat\Payment\Address;
// if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') === false) {
//     exit('请在微信中打开');
// }
define('AUTHKEY', 'user');
/**
 * 共享收货地址需要 **用户 AccessToken** 对象,因此必需授权
 */
if (!isset($_SESSION[AUTHKEY])) {
    $client = new Client($wechat);
    if (!isset($_GET['code'])) {
        $callback = EXAMPLE_URL . 'payment-address.php';
        header('Location: ' . $client->getAuthorizeUrl($callback, 'snsapi_userinfo'));
    } else {
        $token = $client->getAccessToken($_GET['code']);
        $_SESSION[AUTHKEY] = $token;
    }
}
/**
 * 生成共享收货地址 JS 配置文件
 */
$o = new Address($_SESSION[AUTHKEY]);
$configJSON = $o->getConfig();
?>
<!DOCTYPE html>
<html lang="en">