36 lines
979 B
PHP
36 lines
979 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Exceptions\BizException;
|
|
use EasyWeChat\Factory;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
class WxMpService
|
|
{
|
|
public static function make()
|
|
{
|
|
return new static();
|
|
}
|
|
|
|
/**
|
|
* 发货信息录入
|
|
* https://developers.weixin.qq.com/miniprogram/dev/server/API/order_shipping/api_uploadshippinginfo.html
|
|
*/
|
|
public function uploadShippingInfo(array $data)
|
|
{
|
|
$app = Factory::miniProgram(config('wechat.mini_program.default'));
|
|
$accessToken = $app->access_token->getToken()['access_token'];
|
|
$url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $accessToken;
|
|
$response = Http::post($url, $data);
|
|
|
|
$response->throw();
|
|
|
|
$result = $response->json();
|
|
$code = data_get($result, "errcode");
|
|
if ($code != 0) {
|
|
throw new BizException("失败: (".$code.")" . data_get($result, "errmsg"));
|
|
}
|
|
}
|
|
}
|