<?php
header("Content-type: text/html; charset=utf-8");

function gbk_to_utf8($str){
    return mb_convert_encoding($str, 'utf-8', 'gbk');
}

$touser  = $_GET['touser'];  			 //推送者
$aywxbiaoti  ='您的产品已成功卖出！';  	 //标题
$aywxend  = '有任何疑问欢迎咨询客服人员QQxxxxxxx';  			 //底部内容 

$aywxchengjiao  = $_GET['aywxchengjiao'];//成交方
$aywxshangpin  = $_GET['aywxshangpin'];  //商品名称
$aywxshuliang  = $_GET['aywxshuliang'];  //成交数量
$aywxjin  = $_GET['aywxjin']; 			 //成交金额
$aywxshijian  = $_GET['aywxshijian'];    //成交时间

$access_token = $_GET['access_token'];

$result = _reply_customer($touser,$aywxbiaoti,$aywxend,$aywxchengjiao,$aywxshangpin,$aywxshuliang,$aywxjin,$aywxshijian,$access_token);

	function _reply_customer($touser,$aywxbiaoti,$aywxend,$aywxchengjiao,$aywxshangpin,$aywxshuliang,$aywxjin,$aywxshijian,$access_token){
	//$APPID="";
	//$APPSECRET="";
    //$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
	//$ch = curl_init();
	//curl_setopt($ch, CURLOPT_URL, $url);
	//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
	//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 
	//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	//$output = curl_exec($ch);
	//curl_close($ch);
	//$jsoninfo = json_decode($output, true);
	//$access_token = $jsoninfo["access_token"];
    
	
	
	 
    $data = ' {
           "touser":"'.$touser.'",
           "template_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
           "url":"",            
           "data":{
                   "first": {
                       "value":"'.gbk_to_utf8($aywxbiaoti).'",
                       "color":"#173177"
                   },
                   "keyword1": {
                       "value":"'.gbk_to_utf8($aywxchengjiao).'",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"'.gbk_to_utf8($aywxshangpin).'",
                       "color":"#173177"
                   },
                   "keyword3": {
                       "value":"'.gbk_to_utf8($aywxshuliang."笔").'",
                       "color":"#173177"
                   },
				   
                   "keyword4": {
                       "value":"'.gbk_to_utf8($aywxjin."元").'",
                       "color":"#173177"
                   },
                   "keyword5": {
                       "value":"'.$aywxshijian.'",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"'.gbk_to_utf8($aywxend).'",
                       "color":"#173177"
                   }
           }
       }';
	
	
    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
	
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($curl);
	
	echo $result;
	
	
}
?>
