package hls.plugin.weixin.qiye;

import hls.plugin.weixin.common.GetPropertiesValue;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WeixinServlet extends HttpServlet
{
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
  {
    GetPropertiesValue gp = new GetPropertiesValue();
    System.out.println("11111");
    String mediaId = request.getParameter("mediaId");
    String pck_id = request.getParameter("pck_id");
    String id = (String)gp.GetValue().get("appid");
    String secret = (String)gp.GetValue().get("secret");
    String winXinSavePath = (String)gp.GetValue().get("winXinSavePath");
    String userId = request.getParameter("userId");
    String tableName = request.getParameter("tableName");
    String table_pk_value = request.getParameter("table_pk_value");

    new WeixinDownload(); Map map = WeixinDownload.weiDownload(id, secret, mediaId, winXinSavePath);
    String fileName = (String)map.get("fileName");
    String filetype = (String)map.get("filetype");
    String fileSize = (String)map.get("fileSize");
    try {
      new WeiImagePostTo().send(mediaId, pck_id, fileName, filetype, fileSize, userId, tableName, table_pk_value);
    } catch (Exception e) {
      e.printStackTrace();
    }

    PrintWriter pw = response.getWriter();
    pw.println("OK!!");
    pw.flush();
    pw.close();
  }

  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request, response);
  }
}