// +---------------------------------------------------------------------- declare (strict_types = 1); namespace app\common\service; use app\common\model\Wechat; /** * 小程序订阅服务类 * Class Order * @package app\common\service */ class XcxSubscribe extends BaseService { /** * 小程序订阅推送 * @param $openid 微信用户的openid * @param $template_id 推送模版ID * @param $page 跳转地址 * @param $dataJson 推送内容参数 * @author: zjwhust * @Time: 2022/6/17 11:20 */ public static function subscribe($openid,$template_id,$page,$dataJson){ //$template_id = 'M4Nw40B4Hpn4C8NkCiBDajEqz1St_CRRjGlkxDOVP1g'; //$openid = 'shdfjshhjashjkhfjkshdfkjhsljdj'; //$page = 'pages/activity/pages/groupShopping/groupFission/groupFission?shareId=1'; //$dataJson = ['thing1'=>["value"=>"拼团有礼"],'thing3'=>["value"=>'活动已结束,去看看活动结果']]; $weixinToken = (new Wechat)->weixinTokenCache(); $accessToken = $weixinToken['access_token']; $url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" . $accessToken; $data['touser']= $openid; $data['template_id'] = $template_id; $data['page'] = $page; $data['miniprogram_state'] = env('APP_ENV')=="production"?'formal':'trial'; $data['data']= $dataJson; post_curl($url,json_encode($data)); } }