Shipping.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\library\wechat;
  13. use cores\exception\BaseException;
  14. /**
  15. * 发货信息管理接口
  16. * Class Shipping
  17. * @package app\library
  18. */
  19. class Shipping extends WxBase
  20. {
  21. /**
  22. * 发货信息录入接口
  23. * api文档: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html
  24. * @throws BaseException
  25. */
  26. public function uploadShippingInfo(array $params)
  27. {
  28. // 微信接口url
  29. $accessToken = $this->getAccessToken();
  30. $apiUrl = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token={$accessToken}";
  31. // 执行请求
  32. $result = $this->post($apiUrl, $this->jsonEncode($params));
  33. // 记录日志
  34. log_record(['name' => '微信小程序-发货信息录入接口', 'url' => $apiUrl, 'params' => $params, 'result' => $result]);
  35. // 返回结果
  36. $response = $this->jsonDecode($result);
  37. if (!isset($response['errcode'])) {
  38. $this->error = 'not found errcode';
  39. return false;
  40. }
  41. if ($response['errcode'] != 0) {
  42. $this->error = $response['errmsg'];
  43. return false;
  44. }
  45. return $response;
  46. }
  47. /**
  48. * 消息跳转路径设置接口
  49. * api文档: https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/order-shipping/order-shipping.html#%E5%85%AD%E3%80%81%E6%B6%88%E6%81%AF%E8%B7%B3%E8%BD%AC%E8%B7%AF%E5%BE%84%E8%AE%BE%E7%BD%AE%E6%8E%A5%E5%8F%A3
  50. * @throws BaseException
  51. */
  52. public function setMsgJumpPath(array $params)
  53. {
  54. // 微信接口url
  55. $accessToken = $this->getAccessToken();
  56. $apiUrl = "https://api.weixin.qq.com/wxa/sec/order/set_msg_jump_path?access_token={$accessToken}";
  57. // 执行请求
  58. $result = $this->post($apiUrl, $this->jsonEncode($params));
  59. // 记录日志
  60. log_record(['name' => '微信小程序-消息跳转路径设置接口', 'url' => $apiUrl, 'params' => $params, 'result' => $result]);
  61. // 返回结果
  62. $response = $this->jsonDecode($result);
  63. if (!isset($response['errcode'])) {
  64. $this->error = 'not found errcode';
  65. return false;
  66. }
  67. if ($response['errcode'] != 0) {
  68. $this->error = $response['errmsg'];
  69. return false;
  70. }
  71. return $response;
  72. }
  73. }