Skip to content

Latest commit

 

History

History
221 lines (184 loc) · 16.4 KB

readme-cn.md

File metadata and controls

221 lines (184 loc) · 16.4 KB

Laravel-Mixin-SDK


Mixin-Network SDK for Laravel 5

框架要求

  1. Laravel >= 5.1
  2. Composer
  3. PHP >= 7.0

Installation

$ composer require exinone/laravel-mixin-sdk -vvv

配置

  1. 如果你的 Laravel >= 5.5,可跳过第一步,从第二步开始即可。否则需要在 config/app.php 中注册 ServiceProvider 和 Facade。
'providers' => [
    ...
    ExinOne\MixinSDK\MixinSDKServiceProvider::class,
],
'aliases' => [
    ...
    'MixinSDK' => ExinOne\MixinSDK\Facades\MixinSDK::class,
]
  1. 创建配置文件
$ php artisan vendor:publish --provider="ExinOne\MixinSDK\MixinSDKServiceProvider"
  1. 填写配置,你可以选择如下几种方法中的一种来配置
    1. 填写 config/mixin-sdk.php.env 配置

      // 账号配置信息
      'keys'    => [
      // 默认使用名为 `default` 的配置
          'default' => [
              'mixin_id'      => env('MIXIN_SDK_MIXIN_ID'),
              'client_id'     => env('MIXIN_SDK_CLIENT_ID'),
              'client_secret' => env('MIXIN_SDK_CLIENT_SECRET'),
              'pin'           => env('MIXIN_SDK_PIN'),
              'pin_token'     => env('MIXIN_SDK_PIN_TOKEN'),
              'session_id'    => env('MIXIN_SDK_SESSION_ID'),
              'private_key'   => str_replace("\\n", "\n", env('MIXIN_SDK_PRIVATE_KEY')),  //import your private_key
              'safe_key'      => env('MIXIN_SDK_SAFE_KEY'),
          ],
          'myConfig-A'=>[
              ...
          ]
      ],

      此后,调用时就自动载入以上配置。

      // 默认使用 'default'
      MixinSDK::user()->readProfile();
      // 在之后的调用中你就可以这样切换
      MixinSDK::use('myConfig-A')->user()->readProfile();

      如果不想私钥被记录到 VCS 中,可以参考此处进行配置

    2. 你也可以不在 config/mixin-sdk.php 中进行任何配置,以如下方式调用即可

      // 使用 setConfig 方法,保存配置
      MixinSDK::setConfig('myConfig-A',$config0);
      MixinSDK::setConfig('myConfig-B',$config1);
      // 在之后的调用中你就可以
      MixinSDK::use('myConfig-A')->user()->readProfile();
      
      //-------
      // 或者更加简洁一些,直接使用 use 方法后,链式调用其他方法
      MixinSDK::use('myConfig-A',$config)->user()->readProfile();
      // 在之后的调用中你就可以
      MixinSDK::use('myConfig-A')->user()->readProfile();
    3. 你也可以在项目中封装自己的方法来更加方便的切换配置。

使用

调用

code description module Mixin Network Docs
MixinSDK::pin()->updatePin($oldPin, $pin) 更新 Pin 码 Pin link
MixinSDK::pin()->verifyPin($pin) 验证 Pin 码 Pin link
--- -- --
--- -- --
--- -- --
MixinSDK::user()->readProfile() 读取当前账号信息 User link
MixinSDK::user()->updateProfile(string $full_name, string $avatar_base64 = '') 更新账号信息 User link
MixinSDK::user()->updatePreferences(string $receive_message_source, string $accept_conversation_source) 更新隐私设置 User link
MixinSDK::user()->rotateQRCode() 更换 QRCode User link
MixinSDK::user()->readFriends() 读取好友 User link
--- -- --
--- -- --
--- -- --
MixinSDK::wallet()->createAddress(string $asset_id, string $public_key, $pin, $label, bool $isEOS = false) 创建一个 address Wallet link
MixinSDK::wallet()->readAddresses(string $assetId) 获取某个 asset 的全部地址 Wallet link
MixinSDK::wallet()->readAddress(string $addressId) 获取某个 address 的信息 Wallet link
MixinSDK::wallet()->deleteAddress(string $addressId, $pin) 删除一个 address Wallet link
MixinSDK::wallet()->readAssets() 获取当前用户全部的 assets 信息 Wallet link
MixinSDK::wallet()->readAsset(string $assetId) 获取当前用户某个 asset 的信息 Wallet link
MixinSDK::wallet()->deposit(string $assetId) deposit (The api same as wallet()->readAsset) Wallet link
MixinSDK::wallet()->withdrawal(string $addressId, $amount, $pin, $memo = '', $tracd_id = null) 转账到某个 address Wallet link
MixinSDK::wallet()->transfer(string $assetId, string $opponentId, $pin, $amount, $memo = '', $tracd_id = null) 转账给某个用户 Wallet link
MixinSDK::wallet()->verifyPayment(string $asset_id, string $opponent_id, $amount, string $trace_id) 验证支付 Wallet link
MixinSDK::wallet()->readTransfer(string $traceId) 获取转账详情 Wallet link
MixinSDK::wallet()->readAssetFee(string $assetId) 获取资产提现费率 Wallet link
MixinSDK::wallet()->readUserSnapshots($limit = null, string $offset = null, string $asset = '', string $order = 'DESC') 获取当前用户某个资产全部的 snapshots Wallet link
MixinSDK::wallet()->readUserSnapshot(string $snapshotId) 获取当前用户某个 snapshot 的信息 Wallet link
--- -- --
--- -- --
--- -- --
MixinSDK::network()->readUser($userId) 获取某个用户的信息 Network link
MixinSDK::network()->readUsers(array $userIds) 获取多个用户的信息 Network link
MixinSDK::network()->searchUser($item) search user Network link
MixinSDK::network()->readNetworkAsset(string $assetId) read network asset Network link
MixinSDK::network()->readNetworkSnapshots($limit = null, string $offset = null, string $asset = '', string $order = 'DESC') read network snapshots Network link
MixinSDK::network()->readNetworkSnapshot(string $snapshotId) read network snapshot Network link
MixinSDK::network()->createUser($fullName) 在 Mixin Network 上创建用户 Network link
MixinSDK::network()->externalTransactions($asset, $public_key, $limit, $offset, $account_name) read external transactions Network link
MixinSDK::network()->createAttachments() create attachments Network link
MixinSDK::netwo rk()->mixinNetworkChainsSyncStatus() 获取 Mixin Network 当前的区块同步状态 Network
MixinSDK::network()->topAsset() top asset Network link
MixinSDK::network()->requestAccessToken(string $code) use code request access token Network link
MixinSDK::network()->accessTokenGetInfo(string $access_token) use access token get info Network link
MixinSDK::network()->accessTokenGetAssets(string $access_token) use access token get assets info Network link
MixinSDK::network()->accessTokenGetContacts(string $access_token) use access token get contact info Network link
MixinSDK::network()->searchAssets(string $snapshotId) 搜索资产 Network link
--- -- --
--- -- --
--- -- --
MixinSDK::message()->sendText($user_id, $data, $category , $conversation_id) 发送文本消息 Message link
MixinSDK::message()->sendContact($user_id, $contact_id, $category, $conversation_id) 发送用户名片 Message link
MixinSDK::message()->sendAppButtonGroup($user_id, $data, $category, $conversation_id) 发送 App Button Group (最多三个) Message link
MixinSDK::message()->sendAppCard($user_id, $data, $category, $conversation_id) 发送 App Card Message link
MixinSDK::message()->askMessageReceipt($message_id) 确认消息是否送达 Message link
MixinSDK::message()->sendBatchMessage($user_id, $data, $category , $conversation_id) 群发消息 Message link
--- -- --
--- -- --
--- -- --
MixinSDK::getOauthUrl($user_id, $data, $category = 'CONTACT', $conversation_id = null) 获取 Oauth Url other link
MixinSDK::getPayUrl($asset_id, $amount, $trace_id, $memo, $client_id = null) 生成一个支付 Url other link
MixinSDK::getConfig($configGroupName='') 查看一个或者全部配置 other

异常

在 MixinNetwork 的返回体中如果存在 error ,则会直接抛出一个 ExinOne\MixinSDK\Exceptions\MixinNetworkRequestException 异常。使用者需要对这个异常进行捕获并处理。

try {
    //如果这里转账失败将会抛出错误
    MixinSDK::wallet()->transfer($asset_id, $opponent_id, $pin, $amount, $memo);
} catch (MixinNetworkRequestException $e) {
    // 此处的 errCode 和 errMessage 与 MixinNetwork 一致,可以参阅下方官方链接
    $errCode    = $e->getCode();
    $errMessage = $e->getMessage();
    ...
} catch (\Throwable $e) {
    ...
}

MixinNetwork Error Codes

其他的异常

class description
ExinOne\MixinSDK\Exceptions\MixinNetworkRequestException Api 请求失败
ExinOne\MixinSDK\Exceptions\NotFoundConfigException 未找到指定的配置组
ExinOne\MixinSDK\Exceptions\LoadPrivateKeyException 私钥格式等错误
ExinOne\MixinSDK\Exceptions\ClassNotFoundException 寻找指定的 module 失败

WARNING

  1. 进行如下操作可以配置 iterator, 在加密 PIN 时会使用到这个变量。在大部分时候,这个变量基本不需要修改。如果需要修改这个变量,请务必知道你在做什么。关于 iterator 更详细的说明

    $iterator = [time()];
    // 如果是在 MixinSDK::pin()->updatePin($oldPin,$pin) 中使用,
    // $iterator 需要是有两个元素的数组, 即 count($iterator) == 2
    
    MixinSDK::wallet()->setIterator($iterator)->transfer($asset_id, $opponent_id, $pin, $amount, $memo);
    // 默认使用 microtime(true) * 100000 作为 iterator
  2. 获取原始结果

    $mixinSdk->wallet()->setRaw(true)->transfer($asset_id, $opponent_id, $pin, $amount, $memo);
    // 返回 MixinNetwork 的 原始 Response 内容

Alternatives

[exinone/mixin-sdk-php]

[zamseam/mixin]

LICENSE

MIT