XcxSubscribe.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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\service;
  13. use app\common\model\Wechat;
  14. /**
  15. * 小程序订阅服务类
  16. * Class Order
  17. * @package app\common\service
  18. */
  19. class XcxSubscribe extends BaseService
  20. {
  21. /**
  22. * 小程序订阅推送
  23. * @param $openid 微信用户的openid
  24. * @param $template_id 推送模版ID
  25. * @param $page 跳转地址
  26. * @param $dataJson 推送内容参数
  27. * @author: zjwhust
  28. * @Time: 2022/6/17 11:20
  29. */
  30. public static function subscribe($openid,$template_id,$page,$dataJson){
  31. //$template_id = 'M4Nw40B4Hpn4C8NkCiBDajEqz1St_CRRjGlkxDOVP1g';
  32. //$openid = 'shdfjshhjashjkhfjkshdfkjhsljdj';
  33. //$page = 'pages/activity/pages/groupShopping/groupFission/groupFission?shareId=1';
  34. //$dataJson = ['thing1'=>["value"=>"拼团有礼"],'thing3'=>["value"=>'活动已结束,去看看活动结果']];
  35. $weixinToken = (new Wechat)->weixinTokenCache();
  36. $accessToken = $weixinToken['access_token'];
  37. $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $accessToken;
  38. $data['touser']= $openid;
  39. $data['template_id'] = $template_id;
  40. $data['page'] = $page;
  41. $data['miniprogram_state'] = env('APP_ENV')=="production"?'formal':'trial';
  42. $data['data']= $dataJson;
  43. post_curl($url,json_encode($data));
  44. }
  45. }