<?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'];  			//推送者
$access_token = $_GET['access_token'];

$wxtop  = $_GET['wxtop'];   	 		//标题
$wx1  = $_GET['wx1'];  					//投诉订单
$wx2  = $_GET['wx2'];  					//投诉类别
$wxend  = $_GET['wxend'];			 	//底部内容 


$result = _reply_customer($touser,$wxtop,$wx1,$wx2,$wxend,$access_token);


	function _reply_customer($touser,$wxtop,$wx1,$wx2,$wxend,$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":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
           "url":"",            
           "data":{
                   "first": {
                       "value":"'.gbk_to_utf8($wxtop).'",
                       "color":"#173177"
                   },
                   "keyword1": {
                       "value":"'.gbk_to_utf8($wx1).'",
                       "color":"#173177"
                   },
                   "keyword2": {
                       "value":"'.gbk_to_utf8($wx2).'",
                       "color":"#173177"
                   },
                   "remark":{
                       "value":"'.gbk_to_utf8($wxend).'",
                       "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;
	
	
}
?>
