Shoping.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\library\wechat\wow;
  10. use app\common\library\wechat\WxBase;
  11. /**
  12. * 微信好物圈-收藏接口
  13. * Class Shoping
  14. * @url https://wsad.weixin.qq.com/wsad/zh_CN/htmledition/order/html/document/cartlist/import.part.html
  15. * @package app\common\library\wechat\wow
  16. */
  17. class Shoping extends WxBase
  18. {
  19. /**
  20. * 导入商品收藏
  21. * @param string $openId
  22. * @param array $productList
  23. * @return bool
  24. * @throws \app\common\exception\BaseException
  25. */
  26. public function addList($openId, $productList)
  27. {
  28. // 微信接口url
  29. $accessToken = $this->getAccessToken();
  30. $url = "https://api.weixin.qq.com/mall/addshoppinglist?access_token={$accessToken}";
  31. // 请求参数
  32. $params = $this->jsonEncode([
  33. 'user_open_id' => $openId,
  34. 'sku_product_list' => $productList
  35. ]);
  36. // 执行请求
  37. $result = $this->post($url, $params);
  38. // 记录日志
  39. $this->doLogs(['describe' => '新增好物圈商品收藏', 'url' => $url, 'params' => $params, 'result' => $result]);
  40. // 返回结果
  41. $response = $this->jsonDecode($result);
  42. if (!isset($response['errcode'])) {
  43. $this->error = 'not found errcode';
  44. return false;
  45. }
  46. if ($response['errcode'] != 0) {
  47. $this->error = $response['errmsg'];
  48. return false;
  49. }
  50. return true;
  51. }
  52. /**
  53. * 删除商品收藏
  54. * @param $openId
  55. * @param $productList
  56. * @return bool
  57. * @throws \app\common\exception\BaseException
  58. */
  59. public function delete($openId, $productList)
  60. {
  61. // 微信接口url
  62. $accessToken = $this->getAccessToken();
  63. $url = "https://api.weixin.qq.com/mall/deleteshoppinglist?access_token={$accessToken}";
  64. // 请求参数
  65. $params = [
  66. 'user_open_id' => $openId,
  67. 'sku_product_list' => $productList
  68. ];
  69. // 执行请求
  70. $result = $this->post($url, $this->jsonEncode($params));
  71. // 记录日志
  72. $this->doLogs(['describe' => '删除好物圈商品收藏', 'url' => $url, 'params' => $params, 'result' => $result]);
  73. // 返回结果
  74. $response = $this->jsonDecode($result);
  75. if (!isset($response['errcode'])) {
  76. $this->error = 'not found errcode';
  77. return false;
  78. }
  79. if ($response['errcode'] != 0) {
  80. $this->error = $response['errmsg'];
  81. return false;
  82. }
  83. return true;
  84. }
  85. }