muhanz/shoapi 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

muhanz/shoapi

Composer 安装命令:

composer require muhanz/shoapi

包简介

Laravel Shopee Open API SDK

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require StyleCI

Laravel Shopee API SDK (V2)

This is a Unofficial Shopee PHP Client for Laravel 9|10 and currently supported API V2

ShoAPi lets you develop Shopee Open API in Laravel. ShoAPi is an HTTP-based interface created for developers interested Shopee Open API. To learn more about the Shopee Open API, please consult the Introduction on the official Shopee Open Platform site.

Installation

Via Composer

$ composer require muhanz/shoapi

Before Start

Configure your variables in your .env (recommended) or you can publish the config file and change it there.

SHOPEE_PRODUCTION=false // Default
SHOPEE_HOST_URL='https://partner.shopeemobile.com'
SHOPEE_SANDBOX_HOST_URL='https://partner.test-stable.shopeemobile.com'
SHOPEE_CALLBACK_URL='/shopee/auth/get_access_token' // Example: for redirect after auth
SHOPEE_PARTNER_ID=<YOUR_PARTNER_ID>
SHOPEE_PARTNER_KEY=<YOUR_PARTNER_KEY>

(Optional) You can publish the config file via this command:

php artisan vendor:publish --provider="Muhanz\Shoapi\ShoapiServiceProvider" --tag="shoapi.config"

Authorization and Authentication

// Add this facades on top controller
use Muhanz\Shoapi\Facades\Shoapi;

public function auth_partner()
{
    return Shoapi::call('shop')->access('auth_partner')->redirect(); // auto redirect
    
    // or
    
    return Shoapi::call('shop')->access('auth_partner')->getUrl();
    
    // response:
    // https://partner.test-stable.shopeemobile.com/api/v2/shop/auth_partner?partner_id=partner_idtimestamp=1697215282&sign=sign_code&redirect=redirect_url   
}

For cancel/disconnet auth partner

return Shoapi::call('shop')->access('cancel_auth_partner')->redirect();

Get Access Token & Refresh Access Token

The access_token is a dynamic token, and you need to pass access_token to call non-public APIs. Each access_token is valid for 4 hours and can be used multiple times within 4 hours. However, you need to refresh the access token by calling RefreshAccessToken before it expires in order to obtain a new access_token.

Refresh_token is a parameter used to refresh access_token. Each refresh_token is valid for 30 days.

⚠️ Note: The access_token and refresh_token of each shop_id and merchant_id need to be saved separately.

Get Access Token:

// After authorization, the front-end page will redirect to the redirect URL in your authorization link:
// https://open.shopee.com/?code=xxxxxxxxxx&shop_id=xxxxxx

$params =  [
	'code'  =>  "54494572544875766********", 
	'shop_id'  =>  (int)  000000,
];

$response = Shoapi::call('auth')
		->access('get_access_token')
		->shop(000000)
		->request($params)
		->response();
				
dd($response);

Get Refresh Access Token:

$params =  [
	'refresh_token'  =>  "527a424f54494572544875766*******",
	'shop_id'  =>  (int)  000000,
];

$response =  Shoapi::call('auth')
		->access('refresh_access_token')
		->shop(000000)
		->request($params)
		->response();

dd($response);

Example Response:

{
	api_status:"success",
	partner_id:000000,
	refresh_token:"527a424f54494572544875766*******",
	access_token:"786b4c74526e52426555616e*******",
	expire_in:14400,
	request_id:"84ec4d8971735d62dca40c0*******",
	shop_id:000000
}

Basic Usage

// Add this facades on top controller
use Muhanz\Shoapi\Facades\Shoapi;

public function get_shop_info()
{
	
	// path api: /api/v2/shop(use in call)/get_shop_info(use in access)

  return Shoapi::call('shop')
		->access('get_shop_info', <YOUR_ACCESS_TOKEN>)
		->shop(<YOUR_SHOP_ID>)
		->response();
}

Other Example:

// Add this facades on top controller
use Muhanz\Shoapi\Facades\Shoapi;

public  function  get_category()
{

	$params =  [
		'language'  =>  'id'  // en
	];

	$response = Shoapi::call('product')
			->access('get_category',  <YOUR_ACCESS_TOKEN>)
			->shop(<YOUR_SHOP_ID>)
			->request($params)
			->response();
	dd($response);
}

Example Response:

{
	api_status:"success",
	category_list:[
		{
			category_id:100001,
			parent_category_id:0,
			original_category_name:"Health",
			display_category_name:"Kesehatan",
			has_children:true

		}
	]
}

Support Methods

Currently supported all methods exclude GlobalProduct(CB seller only) please open Shopee Open Platform

Service (call) Method (access)
Product add_item, get_category and 35 others
Global Product(CB seller only) - Not Tested
MediaSpace upload_image, upload_video, etc
Shop get_info_shop, get_profile, update_profile, etc
Merchant get_merchant_info, get_shop_list_by_merchant, etc
Order get_order_list, get_order_detail and 11 others
Logistics get_shipping_parameter, get_tracking_number, and 14 others
First Miles get_unbind_order_list, get_detail, etc
Payment get_escrow_detail, set_shop_installment_status, etc
Discount add_discount, add_discount_item, etc
Bundle Deal add_bundle_deal, add_bundle_deal_item, etc
Add-On Deal add_add_on_deal, add_add_on_deal_main_item, etc
Voucher add_voucher, delete_voucher, etc
Follow Prize add_follow_prize, delete_follow_prize, etc
Top Picks get_top_picks_list, add_top_picks, etc
Shop Category add_shop_category, get_shop_category_list, etc
Returns get_return_detail, get_return_list, etc
Account Health shop_performance, shop_penalty
Public get_shops_by_partner, get_access_token,refresh_access_token, etc
Push set_app_push_config, get_app_push_config

Documentation

Please refer to the official documentation Shopee Open Platform

Change log

Please see the changelog for more information on what has changed recently.

Contributing

Please see contributing.md for details and a todolist.

Credits

License

MIT. Please see the license file for more information.

muhanz/shoapi 适用场景与选型建议

muhanz/shoapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 290 次下载、GitHub Stars 达 33, 最近一次更新时间为 2023 年 10 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「Shoapi」 「Shopee API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 muhanz/shoapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 muhanz/shoapi 我们能提供哪些服务?
定制开发 / 二次开发

基于 muhanz/shoapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 290
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 33
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 33
  • Watchers: 3
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-10-13