Shoping.php 2.5 KB

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