微信小程序发送订阅消息

1、微信小程序

uni.requestSubscribeMessage({
	//此处填写刚才申请模板的模板ID
	tmplIds: ['UcjeP3a8vDFKpG6v56xfOK39ByqkhXCkkUoN1_Jsj8s'],
	success (res) {
		console.log(res)
	}
})

2、php

/**
     * 微信通知
     * */
    public function wx_tz($orderid){
        $system = Db::query("select * from ims_zh_jdgjb_system where id = 2");
        $appid = $system[0]['appid'];
        $secret = $system[0]['appsecret'];
        $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
        $res = curl_exec($ch);
        curl_close($ch);
        $tmptoken = json_decode($res);
        $token = $tmptoken->access_token;
        $order = Db::query("select * from ims_zh_jdgjb_order where id='{$orderid}'");
        $name = '';
        if($order[0]['status'] == 1){
            $name = '已付款';
        }
        if($order[0]['status'] == 4){
            $name = '完成';
        }
        if($order[0]['status'] == 5){
            $name = '入住';
        }
        $data = array(
            "touser"=>$order[0]['openid'],
            "template_id"=>"UcjeP3a8vDFKpG6v56xfOK39ByqkhXCkkUoN1_Jsj8s",
            "page"=>"pages/index/index",
            "miniprogram_state"=>"miniprogram_state",
            "lang"=>"zh_CN",
            'data'=>array(
                'thing1'=>array('value'=>$order[0]['seller_name']),
                'phrase2'=>array('value'=>$name),
                'amount9'=>array('value'=>$order[0]['price']),
                'thing19'=>array('value'=>$order[0]['room_type']),
            ),
        );
        $url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$token;
        $re = $this->http_request($url,$data);
        return $re;
    }

    public function http_request($url, $data = null)
    {
        $data = json_encode($data);
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);

        if (!empty($data)) {
            curl_setopt($curl, CURLOPT_POST, TRUE);
            curl_setopt($curl, CURLOPT_POSTFIELDS,$data);
            curl_setopt($curl, CURLOPT_HTTPHEADER, array(
                'Content-Type: application/json'
            ));
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大得369

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值