import java.io.IOException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import com.alibaba.fastjson.JSONObject;
public class WeixinQuery2 {
private static final String token = "";
public static void main(String[] args) throws ClientProtocolException, IOException {
JSONObject data2 = new JSONObject();
JSONObject keyword1 = new JSONObject();
keyword1.put("value", " ");
keyword1.put("color", "#173177");
data2.put("keyword1", keyword1);
JSONObject keyword2 = new JSONObject();
keyword2.put("value", " ");
keyword2.put("color", "#173177");
data2.put("keyword2", keyword2);
JSONObject keyword3 = new JSONObject();
keyword3.put("value", " ");
keyword3.put("color", "#173177");
data2.put("keyword3", keyword3);
JSONObject mp_template_msg = new JSONObject();
mp_template_msg.put("appid", "wx2b735862ca820115");
mp_template_msg.put("template_id", "6-qFl65_1frlx0BlxSi4ds9-j5dliCui-3Wubnvo-nc");
mp_template_msg.put("data", data2);
JSONObject body = new JSONObject();
body.put("touser", "ojYObwyuuiRwabs84UOyJOj1ZDzw");
body.put("mp_template_msg", mp_template_msg);
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
httpPost.setEntity(new StringEntity(body.toJSONString(), "UTF-8"));
CloseableHttpClient client = HttpClients.createDefault();
CloseableHttpResponse response = client.execute(httpPost);
String result = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println(result);
}
}
你好,麻烦提供下返回的rid