123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace app\api\controller;
- use app\common\enum\Setting as SettingEnum;
- use app\common\library\express\Kuaidi100;
- use app\api\model\Kuaidi as KuaidiModel;
- use app\common\model\store\Setting as SettingModel;
- use think\facade\Log;
- /**
- * 快递100接口
- * Class Index
- * @package app\api\controller
- */
- class Kuaidi extends Controller
- {
- //订阅请求接口
- public function subscribe(){
- $arg = $this->request->param();
- // 获取快递100配置项
- // 实例化快递100类
- $config = SettingModel::getItem(SettingEnum::DELIVERY);
- if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
- throwError('请先到后台-设置-配送方式 补充物流查询API配置');
- }
- // 实例化快递100类
- $Kuaidi100 = new Kuaidi100($config['kuaidi100']);
- // 请求订阅接口
- $list = $Kuaidi100->subscribe($arg['number'],$arg['type'] ?? 1,$arg['company'],$arg['phone']??'');
- return $this->renderSuccess(compact('list'));
- }
- public function dynamic(){
- $arg = $this->request->param();
- if (empty($arg['name']) || empty($arg['code']) || empty($arg['no'])){
- return $this->renderError('参数错误');
- }
- // 获取快递100配置项
- // 实例化快递100类
- $config = SettingModel::getItem(SettingEnum::DELIVERY);
- if (empty($config['kuaidi100']['customer']) || empty($config['kuaidi100']['key'])) {
- throwError('请先到后台-设置-配送方式 补充物流查询API配置');
- }
- // 实例化快递100类
- $Kuaidi100 = new \app\common\model\Express($config['kuaidi100']);
- // 请求订阅接口
- $list = $Kuaidi100->dynamic($arg['name'],$arg['code'],$arg['no'],$arg['phone'] ?? '');
- if (empty($list)){
- return $this->renderError('查询出错');
- }
- /* //手动保存物流路径
- $kuaidiModle = new \app\api\model\Kuaidi();
- $res = $kuaidiModle->get(['number'=>$arg['no']]);
- if (!empty($res['id'])){
- $json= [
- "status" => "",
- "billstatus" => "",
- "message" => "",
- "lastResult"=>[
- "message"=>"ok",
- "nu"=>$arg['no'],
- "isCheck"=>"1",
- "com"=>$arg['code'],
- "status"=>"200",
- "data"=>$list['list']]
- ];
- $kuaidiModle->updateBase(['json' => serialize($json),'update_time'=>time()], ['id'=>$res['id']]);
- }*/
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 快递推送回调接口
- * @return array
- * @author: zjwhust
- * @Time: 2021/9/29 14:06
- */
- public function callback(){
- $model = new KuaidiModel;
- Log::info('callback:'.':'.json_encode($this->request->param()));
- if ($model->upd($this->request->param())) {
- return json([
- "result"=>true,
- "returnCode"=>"200",
- "message"=>"成功"
- ]);
- }
- return json([
- "result"=>true,
- "returnCode"=>"500",
- "message"=>"没有接收到订单信息"
- ]);
- }
- }
|