本文介绍如何使用微信公众平台客服消息发送接口来发送卡券给用户。
一、卡券格式
卡券的json格式如下
{ "touser":"OPENID", "msgtype":"wxcard", "wxcard":{ "card_id":"123dsdajkasd231jhksad" } }
其中,msgtype为wxcard,而card_id为卡券 ID
二、代码实现
使用方倍工作室的http_request来发送,代码如下
$access_token = "O1AEwcSsQQlPjGlDdI-f_yd8u2mRmpYY_knJaqQ5t5Wl9Wr_TXeWaI0--JPwU3hcjX1GdtpjHn4tAJFmgKeJKOH9K4GPVjcyhR1utGkEAd4RSNiAAAXYT"; $url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$access_token; $openid = "oiPuduCHIBb2aHvZoqSm1t7KbXtw"; //发送卡券 $data = ‘{ "touser":"‘.$openid.‘", "msgtype":"wxcard", "wxcard":{ "card_id":"piPuduM3NHSnSMYgWS-oqGFQbBjM" } }‘; $result = https_request($url,$data); var_dump($result); function https_request($url, $data = null){ $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, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; }
原文地址:https://www.cnblogs.com/txw1958/p/custom-message-send-wxcard.html
时间: 2024-10-01 11:05:42