All Projects → Hanson → Youzan Sdk

Hanson / Youzan Sdk

👍有赞 SDK

Labels

Projects that are alternatives of or similar to Youzan Sdk

Kanvas
Make canvas easier to use in Kotlin 😊
Stars: ✭ 93 (-9.71%)
Mutual labels:  sdk
Quickblox Javascript Sdk
JavaScript SDK of QuickBlox cloud backend platform
Stars: ✭ 98 (-4.85%)
Mutual labels:  sdk
Applicationinsights Dotnet Logging
.NET Logging adaptors
Stars: ✭ 100 (-2.91%)
Mutual labels:  sdk
Go Sdk
Stars: ✭ 94 (-8.74%)
Mutual labels:  sdk
Go Tfe
Terraform Cloud/Enterprise API Client/SDK in Golang
Stars: ✭ 98 (-4.85%)
Mutual labels:  sdk
Wxpay
微信支付 wxpay SDK for Go, 集成简单,功能完善,持续更新。
Stars: ✭ 99 (-3.88%)
Mutual labels:  sdk
Xr871 Old
XR871 SDK
Stars: ✭ 92 (-10.68%)
Mutual labels:  sdk
Weixinsdk
Wlitsoft 框架 - 微信公众号开发工具包(C# 版)
Stars: ✭ 102 (-0.97%)
Mutual labels:  sdk
Applicationinsights Php
Azure Application Insights SDK for PHP
Stars: ✭ 98 (-4.85%)
Mutual labels:  sdk
Shopify Api Php
🚀 Shopify API Client for PHP
Stars: ✭ 100 (-2.91%)
Mutual labels:  sdk
Nim ios uikit
网易云信 iOS UI 组件,提供聊天界面,文本消息,图片消息,语音消息,视频消息,地理位置消息,自定义消息(阅后即焚)等消息示例。#推荐客户得比特币,首次推荐得0.02BTC,连续推荐得0.03BTC/单,上不封顶。点击参与https://yunxin.163.com/promotion/recommend
Stars: ✭ 1,326 (+1187.38%)
Mutual labels:  sdk
Opentok Ruby Sdk
OpenTok Server SDK for Ruby
Stars: ✭ 97 (-5.83%)
Mutual labels:  sdk
Easywechat
📦 一个 PHP 微信 SDK
Stars: ✭ 9,676 (+9294.17%)
Mutual labels:  sdk
Space Sdk
The Space SDK is a JavaScript/Typescript library for building web and mobile applications leveraging Open Web and distributed protocols like IPFS, Textile, GunDB, and Ethereum.
Stars: ✭ 93 (-9.71%)
Mutual labels:  sdk
Invest Openapi Go Sdk
Stars: ✭ 101 (-1.94%)
Mutual labels:  sdk
Algoliasearch Client Android
Algolia Search API Client for Android
Stars: ✭ 92 (-10.68%)
Mutual labels:  sdk
Douyinsdk
抖音 SDK,数据采集,爬虫抓取不是梦
Stars: ✭ 99 (-3.88%)
Mutual labels:  sdk
Go Sdk
A composable toolbox of libraries to build everything from CLIs to enterprise applications.
Stars: ✭ 103 (+0%)
Mutual labels:  sdk
Contentful.php
Official PHP SDK for the Content Delivery API
Stars: ✭ 101 (-1.94%)
Mutual labels:  sdk
Ios Print Sdk
iOS Print SDK. Easily add print on demand functionality to your app within minutes! Print Postcards, Magnets, Photo Prints, Posters, Stickers, T-Shirts, PhotoBooks, etc.
Stars: ✭ 99 (-3.88%)
Mutual labels:  sdk

Youzan SDK

有赞 SDK (支持有赞所有版本)

base on foundation-sdk

Requirement

Installation

// 有赞云最新版支持
composer require hanson/youzan-sdk -vvv

Usage

自用型应用

<?php

$youzan = new \Hanson\Youzan\Youzan([
    'client_id' => '',
    'client_secret' => '',
    'debug' => true, // 调试模式
    'kdt_id' => '', // 店铺ID(仅自用模式下填写)
    'exception_as_array' => true, // 错误返回数组还是异常
    'version' => '4.0.0',
    'log' => [
        'name' => 'youzan',
        'file' => __DIR__.'/youzan.log',
        'level'      => 'debug',
        'permission' => 0777,
    ]
]);

// 获取订单
$result = $youzan->request('youzan.trade.get', ['tid' => 'xxx']);

// 获取门店信息(你可以设置调用api的版本)
$result = $youzan->setVersion('3.0.0')->request('youzan.shop.get');

工具型应用

<?php

$youzan = new \Hanson\Youzan\Youzan([
    'client_id' => '',
    'client_secret' => '',
    'dev_client_id' => '工具型有容器的开发环境 client id', // 仅在 is_dev=true 时有用
    'dev_client_secret' => '工具型有容器的开发环境 client secret', // 仅在 is_dev=true 时有用
    'is_dev' => true, // 默认 false
    'debug' => true,
    'redirect_uri' => 'http://xxx.com',
    'exception_as_array' => true,
    'version' => '4.0.0',
    'log' => [
        'name' => 'youzan',
        'file' => __DIR__.'/youzan.log',
        'level'      => 'debug',
        'permission' => 0777,
    ]
]);

// 解密消息
$youzan->decrypt->decrypt($message);

/**
* 切换开发模式
 *
 * 新版有赞云工具型有容器应用中,同一应用测试环境与正式环境的 client_id 和 client_secret都不一样,故此添加了 dev_client_id,dev_client_secret 和此方法,用于切换不同环境下的开发,默认为false,正式开发可以不调用此方法
 */
$youzan->setDev(true);

// 使用配置中的 prod_client_secret 进行解密
$youzan->decrypt->decryptWithProd($message);

// 获取授权 URL
$url = $youzan->pre_auth->authorizationUrl();

// 重定向到授权页面
$youzan->pre_auth->authorizationRedirect();

// 在重定向页面,你可以获取此次授权账号的 token
$token = $youzan->pre_auth->getAccessToken();

// 也可以通过上面得到的 refresh_token 去刷新令牌
$token = $youzan->pre_auth->refreshToken($token['refresh_token']);

// 创建授权应用
$youzan = $youzan->oauth->createAuthorization($token['token']);

// 店铺信息
$result = $youzan->request('youzan.shop.get');

// 上传图片(4.0以上版本)
$result = $youzan->request('youzan.materials.storage.platform.img.upload', [], ['image' => [file_get_contents('https://i.loli.net/2018/12/17/5c17334487566.jpg')]]);

消息推送

<?php
// 消息结构体
$data = $youzan->push->parse();

// 开发者自行选择性处理,把 "null" 与 "" 转为 null,建议使用
// $data = Helper::toNull($data);

$response = $youzan->push->response();

// $response 为 `Symfony\Component\HttpFoundation\Response` 实例
// 对于需要直接输出响应的框架,或者原生 PHP 环境下
$response->send();

// 而 Laravel 中直接返回即可:
return $response;

升级指南

4.* -> 5.*

* 4.* 的时候会对 api response 做处理,只返回 $response['response'] 部分
* 5.* 以后默认原样返回 youzan api 的 response,不再二次处理,请注意更新业务代码

3.* -> 4.*

* 构造函数设置了 `$config['exception_as_array'] = true;` 错误会返回包含 `error_response` 键名的数组(以前没有)
* 上传图片为 `$youzan->request('youzan.materials.storage.platform.img.upload', [], ['image' => [$bytes]]);`

Help

QQ 群: 570769430

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].