Kuaidi.php 1.5 KB

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