PHP code example of smhsw / easy-bytedance-miniapp

1. Go to this page and download the library: Download smhsw/easy-bytedance-miniapp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

smhsw / easy-bytedance-miniapp example snippets


// 配置好config...

$app = new Application($config);
$code = $app->app_code->get();

$file = fopen(__DIR__ . '/code.png', 'w+');
fwrite($file, $code);
fclose($file);


// 配置好config,获取登录用户openid, session_key

$app = new Application($config);

$openId = 'openid';
$sessionKey = 'session_key';
$kvList = [
    ['key' => 'custom-key', 'value' => 'custom-value']
];

$app->user_storage->set($openId, $sessionKey, $kvList);


// 配置好config,获取登录用户openid, session_key

$app = new Application($config);

$openId = 'openid';
$sessionKey = 'session_key';
$keys = ['custom_key'];

$app->user_storage->remove($openId, $sessionKey, $keys);


// 配置好config

$app = new Application($config);

$data = [
    'app_id' => '800000000001',
    'merchant_id' => '1900000001',
    'timestamp' => 1570694312,
    'sign_type' => 'MD5',
    'out_order_no' => '201900000000000001',
    'total_amount' => 1,
    'product_code' => 'pay',
    'payment_type' => 'direct',
    'trade_type' => 'H5',
    'version' => '2.0',
    'currency' => 'CNY',
    'subject' => '测试订单',
    'body' => '测试订单',
    'uid' => '0000000000000001',
    'trade_time' => 1570585744,
    'valid_time' => 300,
    'notify_url' => '',
    'risk_info' => '{"ip":"120.230.0.0"}',
    'wx_type' => 'MWEB',
    'wx_url' => 'https://wx.tenpay.com/xxx',
    'alipay_url' => 'app_id=2019000000000006&biz_content=xxxx'
];

$app->server->signature($data);
// 0f1e3358a9898d7c4c6c23740251808a