Kuaidi.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\enum\Setting as SettingEnum;
  4. use app\common\library\express\Kuaidi100;
  5. use app\api\model\Kuaidi as KuaidiModel;
  6. use app\common\model\store\Setting as SettingModel;
  7. use think\facade\Log;
  8. /**
  9. * 快递100接口
  10. * Class Index
  11. * @package app\api\controller
  12. */
  13. class Kuaidi extends Controller
  14. {
  15. //订阅请求接口
  16. public function subscribe(){
  17. $arg = $this->request->param();
  18. // 获取快递100配置项
  19. // 实例化快递100类
  20. $config = SettingModel::getItem(SettingEnum::DELIVERY);
  21. if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
  22. throwError('请先到后台-设置-配送方式 补充物流查询API配置');
  23. }
  24. // 实例化快递100类
  25. $Kuaidi100 = new Kuaidi100($config['kuaidi100']);
  26. // 请求订阅接口
  27. $list = $Kuaidi100->subscribe($arg['number'],$arg['type'] ?? 1,$arg['company']);
  28. return $this->renderSuccess(compact('list'));
  29. }
  30. /**
  31. * 快递推送回调接口
  32. * @return array
  33. * @author: zjwhust
  34. * @Time: 2021/9/29 14:06
  35. */
  36. public function callback(){
  37. $model = new KuaidiModel;
  38. Log::info('callback:'.':'.json_encode($this->request->param()));
  39. if ($model->upd($this->request->param())) {
  40. return json([
  41. "result"=>true,
  42. "returnCode"=>"200",
  43. "message"=>"成功"
  44. ]);
  45. }
  46. return json([
  47. "result"=>true,
  48. "returnCode"=>"500",
  49. "message"=>"没有接收到订单信息"
  50. ]);
  51. }
  52. }