This article describes how to send the interface card to send coupons to users micro-channel public platform for customer service messages.
First, the coupon card format
Card vouchers json format is as follows
{ "touser":"OPENID", "msgtype":"wxcard", "wxcard":{ "card_id":"123dsdajkasd231jhksad" } }
Which, msgtype is wxcard, and card_id for the coupon ID card
Second, code implementation
Http_request consumer fold studio transmits, as follows
$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; }