Meituan-Pub-Union is the PHP-SDK of Meituan Distribution Alliance API
$ composer require gaowei-space/meituan-pub-union -vvvBefore using this extension, you need to register an account at Meituan Distribution Alliance, sign a contract and enter to create an application, and obtain the application's app_key and utm_source.
ProvinceAllRequestCitiesRequest from a provinceCategoriesRequestRegionsByDianPingRequestRegionsByMeiTuanRequestSearchDealsRequest for in-store products (Meituan has stopped requesting permissions for this interface, please understand)LinksRequestOrdersAbnormalRequestOrdersCPARequestOrdersCPSRequestSeckillShowInfoRequestSeckillListRequest use GaoweiSpace MeituanPubUnion Api Common Request CitiesRequest ;
use GaoweiSpace MeituanPubUnion Http Client ;
$ app_key = ' xxxxxxxxxx ' ;
$ utm_source = ' xxxxxxxxxx ' ;
// 实例化获取城市的请求类
$ request = new CitiesRequest ();
// 设置省份ID
$ request -> setProvinceId ( 1 );
// 实例客户端类
$ client = new Client ( $ app_key , $ utm_source );
// 发送请求调用接口
$ response = $ client -> syncInvoke ( $ request );For the request parameters, please combine the Meituan Distribution Alliance API document to confirm the parameters to be used, and call the corresponding method of the corresponding request API class to set it.
Each request API class has built-in set prefix for each parameter, such as:
public function setUtmSource ( string $ utmSource ): void
{
$ this -> utmSource = $ utmSource ;
}Call the corresponding method and set the parameter:
$ request -> setUtmSource ( ' *** ' ); The same installation method is used in Laravel, and the configuration is written in config/services.php :
' meituan ' => [
' pub_union ' => [
' app_key ' => env ( ' MEITUAN_PUB_UNION_APP_KEY ' ),
' utm_source ' => env ( ' MEITUAN_PUB_UNION_UTM_SOURCE ' ),
]
]Then configure in .env:
MEITUAN_PUB_UNION_APP_KEY=xxxxxxxxxxxxxxxxxxxxx
MEITUAN_PUB_UNION_UTM_SOURCE=xxxxxxxxxxxxxxxxxxxxx
GaoweiSpaceMeituanPubUnionHttpClient instance: use GaoweiSpace MeituanPubUnion Http Client ;
public function getCities ( Client $ client )
{
$ response = $ client -> syncInvoke ( $ request );
} public function getCities ()
{
$ response = app ( ' MeituanPubUnion ' )-> syncInvoke ( $ request );
}MIT