<commit_before>package so.xunta.web.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import so.xunta.beans.User;
import so.xunta.server.LoggerService;
import so.xunta.server.UserService;
import so.xunta.utils.IdWorker;
import so.xunta.websocket.utils.TemplateMessageUtils;


@Controller
public class SendWeChatTemplateMsgController {
	@Autowired
	LoggerService loggerService;
	@Autowired
	private UserService userService;

	TemplateMessageUtils templateMessageUtils = new TemplateMessageUtils();
	
	static Logger logger = Logger.getRootLogger();

	IdWorker idWorker = new IdWorker(1L, 1L);
	@RequestMapping("/sendMTemplateMsg")
	public void checkUserExist(String userid,String touserid,String content,HttpServletRequest request,HttpServletResponse response) throws IOException{
		logger.debug("模版消息接口被调用时返回的数据：userid="+userid+" touserid="+touserid+" content"+content);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//设置日期格式
		User user=userService.findUser(Long.valueOf(userid));
		String openid=user.getOpenid();
		String username=user.getName();
		logger.debug("模版消息接口被调用时获取的openid和username：openid="+openid+" username="+username);
		//获得两人共同选择的标签，最多显示三个
		String sameSelectTags=sendPost("http://xunta.so:3000/v1/find/users/same/tags/", "my_user_id="+userid+"matched_user_id"+touserid);
		logger.debug("发送模版消息时共同选择的标签："+sameSelectTags);
		String sameSelectTagList="";//模版消息中不能超过显示三个标签
		JSONObject sameSelectTagJsonObject=new JSONObject(sameSelectTags);
		JSONArray sameSelectTagJsonObjectList=sameSelectTagJsonObject.getJSONArray("msg");
		if(sameSelectTagJsonObjectList!=null){
			for(int i=0;i<3;i++){
				sameSelectTagList=sameSelectTagList+","+sameSelectTagJsonObjectList.getJSONObject(i).getString("text");
			}
			if(sameSelectTagJsonObjectList.length()>=3){
				sameSelectTagList=sameSelectTagList+"...";
			}
		}
		logger.debug("模版消息显示的共同选择的标签："+sameSelectTagList);
		String result=templateMessageUtils.sendWechatmsgToUser(
				openid, 
				"<KEY>", <commit_msg>将模版消息方法中log打印问题解决<commit_after>package so.xunta.web.controller;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import so.xunta.beans.User;
import so.xunta.server.LoggerService;
import so.xunta.server.UserService;
import so.xunta.utils.IdWorker;
import so.xunta.websocket.utils.TemplateMessageUtils;


@Controller
public class SendWeChatTemplateMsgController {
	@Autowired
	LoggerService loggerService;
	@Autowired
	private UserService userService;

	TemplateMessageUtils templateMessageUtils = new TemplateMessageUtils();
	
	Logger logger = Logger.getLogger(SendWeChatTemplateMsgController.class);

	IdWorker idWorker = new IdWorker(1L, 1L);
	@RequestMapping("/sendMTemplateMsg")
	public void checkUserExist(String userid,String touserid,String content,HttpServletRequest request,HttpServletResponse response) throws IOException{
		logger.debug("模版消息接口被调用时返回的数据：userid="+userid+" touserid="+touserid+" content"+content);
		
		SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");//设置日期格式
		User user=userService.findUser(Long.valueOf(userid));
		String openid=user.getOpenid();
		String username=user.getName();
		logger.debug("模版消息接口被调用时获取的openid和username：openid="+openid+" username="+username);
		//获得两人共同选择的标签，最多显示三个
		String sameSelectTags=sendPost("http://xunta.so:3000/v1/find/users/same/tags/", "my_user_id="+userid+"matched_user_id"+touserid);
		logger.debug("发送模版消息时共同选择的标签："+sameSelectTags);
		String sameSelectTagList="";//模版消息中不能超过显示三个标签
		JSONObject sameSelectTagJsonObject=new JSONObject(sameSelectTags);
		JSONArray sameSelectTagJsonObjectList=sameSelectTagJsonObject.getJSONArray("msg");
		if(sameSelectTagJsonObjectList!=null){
			for(int i=0;i<3;i++){
				sameSelectTagList=sameSelectTagList+","+sameSelectTagJsonObjectList.getJSONObject(i).getString("text");
			}
			if(sameSelectTagJsonObjectList.length()>=3){
				sameSelectTagList=sameSelectTagList+"...";
			}
		}
		logger.debug("模版消息显示的共同选择的标签："+sameSelectTagList);
		String result=templateMessageUtils.sendWechatmsgToUser(
				openid, 
				"<KEY>", 
{'fraction_non_alphanumeric': 0.11645422943221322, 'fraction_numerical': 0.004248744689069139, 'mean_word_length': 7.448613376835237, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1468072', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1815, 'n_words': 239}