Giter VIP home page Giter VIP logo

bytedance-miniapp's Introduction

EasyByteDance/MiniApp

字节跳动系小程序SDK,参照easy-wechat实现

Build Status codecov Latest Stable Version Latest Unstable Version Total Downloads License

功能

  • 小程序登录
  • 授权信息解密
  • 发送模板消息
  • 获取小程序二维码
  • 设置数据缓存
  • 删除数据缓存
  • 内容安全检查
  • 服务端数据签名

安装

composer require f-oris/easy-bytedance-miniapp

基本使用

参考easy-wechat使用文档,因为是仿着做的,所以小程序各组件提供的方法,含义,用法基本上和easy-wechat一致

获取小程序二维码

// 配置好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

License

MIT License

Copyright (c) 2019-present F.oris [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.