<repo_name>liyuan837/leolder<file_sep>/src/main/java/com/liyuan/demo/controller/HeroController.java
package com.liyuan.demo.controller;

import com.liyuan.demo.entity.Hero;
import com.liyuan.demo.service.HeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:LiYuan
 * @description:
 * @Date:Create in 15:28 2018/2/8
 * @Modified By:
 */
@RestController
@RequestMapping("/hero")
public class HeroController {

    @Autowired
    private HeroService heroService;

    @GetMapping("/get")
    public Map<String,Object> list(){
        Map<String,Object> modelMap = new HashMap<>();
        List<Hero> list = heroService.queryAll();
        modelMap.put("list",list);
        return modelMap;
    }

    @GetMapping("/get/{id}")
    public Map<String,Object> find(@PathVariable("id") Integer id){
        Map<String,Object> modelMap = new HashMap<>();
        Hero hero = heroService.findById(id);
        modelMap.put("hero",hero);
        return modelMap;

    }

    @PostMapping("/post")
    public Map<String,Object> post(@RequestBody Hero hero){
        Map<String,Object> modelMap = new HashMap<>();
        Integer id = heroService.saveHero(hero);
        hero.setId(id);
        modelMap.put("hero",hero);
        return modelMap;
    }

    @PostMapping("/put")
    public Map<String,Object> put(@RequestBody Hero hero){
        Map<String,Object> modelMap = new HashMap<>();
        Integer result = heroService.updateHero(hero);
        modelMap.put("hero",hero);
        return modelMap;
    }
    @GetMapping("/delete/{id}")
    public Map<String,Object> delete(@PathVariable("id") Integer id){
        Map<String,Object> modelMap = new HashMap<>();
        Integer result = heroService.deleteHero(id);
        modelMap.put("result","deleteSuccess");
        return modelMap;

    }

    /**
     * 实现文件上传
     * */
    @RequestMapping(value="/fileUpload",method = RequestMethod.POST)
    @ResponseBody
    public String fileUpload(MultipartFile file){

        if(file.isEmpty()){
            return "false";
        }
        String fileName = file.getOriginalFilename();

        String path = System.getProperty("user.dir") + "/uploadFile" ;
        System.out.println(path);
        File dest = new File(path + "/" + fileName);
        if(!dest.getParentFile().exists()){ //判断文件父目录是否存在
            dest.getParentFile().mkdir();
        }
        try {
            file.transferTo(dest); //保存文件
            return "true";
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "false";
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "false";
        }
    }

    //文件下载相关代码
    @RequestMapping("/download")
    public String downloadFile(HttpServletRequest request, HttpServletResponse response) {
        String fileName = "1.png";// 设置文件名，根据业务需要替换成要下载的文件名
        System.out.println(fileName);
        if (fileName != null) {
            //设置文件路径
            String realPath = "D:/workspace_idea/leolder/leolder/uploadFile/";
            File file = new File(realPath , fileName);
            if (file.exists()) {
                response.setContentType("application/force-download");// 设置强制下载不打开
                response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);// 设置文件名
                byte[] buffer = new byte[1024];
                FileInputStream fis = null;
                BufferedInputStream bis = null;
                try {
                    fis = new FileInputStream(file);
                    bis = new BufferedInputStream(fis);
                    OutputStream os = response.getOutputStream();
                    int i = bis.read(buffer);
                    while (i != -1) {
                        os.write(buffer, 0, i);
                        i = bis.read(buffer);
                    }
                    System.out.println("success");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if (bis != null) {
                        try {
                            bis.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
        return null;
    }

}
<file_sep>/src/main/java/wechat/util/CertHttpUtil.java
package wechat.util;

public class CertHttpUtil {
//
//	private static int socketTimeout = 10000;// 连接超时时间，默认10秒
//	private static int connectTimeout = 30000;// 传输超时时间，默认30秒
//	private static RequestConfig requestConfig;// 请求器的配置
//	private static CloseableHttpClient httpClient;// HTTP请求器
//
//	public static Map<String,String> refundOrder(Order order) throws Exception{
//		//创建退款订单
//		RefundOrder refundOrder = new RefundOrder();
//		refundOrder.setAppid(ConstantsUtil.appid);
//		refundOrder.setMch_id(ConstantsUtil.mchId);
//		refundOrder.setNonce_str(UUID.randomUUID().toString().replace("-", "").substring(0,32));
//		refundOrder.setOut_refund_no(ConstantsUtil.mchId);
//		refundOrder.setOut_refund_no(order.getBackcode());
//		refundOrder.setOut_trade_no(order.getOrdercode());
//		refundOrder.setTotal_fee((int) (1));
//		refundOrder.setRefund_fee((int) (1));
//		refundOrder.setOp_user_id(ConstantsUtil.mchId);
//		refundOrder.setSign(createSign(refundOrder));
//
//		//将集合转换成xml
//		String requestXML =MessageUtil.messageToXml(refundOrder).replace("__", "_");
//		System.out.println("请求："+requestXML);
//		//带证书的post
////		String resXml = CertHttpUtil.postData(ConstantsUtil.refundUrl, requestXML);
//		String resXml = postData(ConstantsUtil.refundUrl, requestXML);
//		System.out.println("结果："+resXml);
//		//解析xml为集合，请打断点查看resXml详细信息
//		Map<String,String> resultMap = MessageUtil.parseXml(resXml);
//
//		return resultMap;
//	}
//
//	/**
//	 * 通过Https往API post xml数据
//	 *
//	 * @param url
//	 *            API地址
//	 * @param xmlObj
//	 *            要提交的XML数据对象
//	 * @return
//	 * @throws Exception
//	 */
//	public static String postData(String url, String xmlObj) throws Exception {
//		// 加载证书
//		try {
//			initCert();
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		String result = null;
//		HttpPost httpPost = new HttpPost(url);
//		// 得指明使用UTF-8编码，否则到API服务器XML的中文不能被成功识别
//		StringEntity postEntity = new StringEntity(xmlObj, "UTF-8");
//		httpPost.addHeader("Content-Type", "text/xml");
//		httpPost.setEntity(postEntity);
//		// 根据默认超时限制初始化requestConfig
//		requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
//				.setConnectTimeout(connectTimeout).build();
//		// 设置请求器的配置
//		httpPost.setConfig(requestConfig);
//		try {
//			HttpResponse response = null;
//			try {
//				response = httpClient.execute(httpPost);
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//			HttpEntity entity = response.getEntity();
//			try {
//				result = EntityUtils.toString(entity, "UTF-8");
//			} catch (IOException e) {
//				e.printStackTrace();
//			}
//		} finally {
//			httpPost.abort();
//		}
//		return result;
//	}
//
//	/**
//	 * 加载证书
//	 *
//	 */
//	private static void initCert() throws Exception {
//		// 证书密码，默认为商户ID
//		String key = ConstantsUtil.mchId;
//		// 证书的路径
//		String path = ConstantsUtil.certPath;
//		// 指定读取证书格式为PKCS12
//		KeyStore keyStore = KeyStore.getInstance("PKCS12");
//		// 读取本机存放的PKCS12证书文件
//		FileInputStream instream = new FileInputStream(new File(path));
//		try {
//			// 指定PKCS12的密码(商户ID)
//			keyStore.load(instream, key.toCharArray());
//		} finally {
//			instream.close();
//		}
//		SSLContext sslcontext = SSLContexts.custom()
//				.loadKeyMaterial(keyStore, key.toCharArray()).build();
//		// 指定TLS版本
//		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
//				sslcontext, new String[] { "TLSv1" }, null,
//				SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
//		// 设置httpclient的SSLSocketFactory
//		httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
//	}
//
//	// 生成退款单sign
//	private static String createSign(RefundOrder refundOrder) {
//		SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
//		/**
//		 * 组装请求参数 按照ASCII排序
//		 */
//		parameters.put("appid", refundOrder.getAppid());
//		parameters.put("mch_id", refundOrder.getMch_id());
//		parameters.put("nonce_str", refundOrder.getNonce_str());
//		parameters.put("out_trade_no", refundOrder.getOut_trade_no());
//		parameters.put("out_refund_no", refundOrder.getOut_refund_no());
//		parameters.put("total_fee", refundOrder.getTotal_fee());
//		parameters.put("refund_fee",refundOrder.getRefund_fee());
//		parameters.put("op_user_id", refundOrder.getOp_user_id());
//
//		StringBuffer sb = new StringBuffer();
//		Set es = parameters.entrySet();// 所有参与传参的参数按照accsii排序（升序）
//		Iterator it = es.iterator();
//		while (it.hasNext()) {
//			Map.Entry entry = (Map.Entry) it.next();
//			String k = (String) entry.getKey();
//			Object v = entry.getValue();
//			if (null != v && !"".equals(v) && !"sign".equals(k)
//					&& !"key".equals(k)) {
//				sb.append(k + "=" + v + "&");
//			}
//		}
//		sb.append("key=" + ConstantsUtil.payKey);
//		String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
//		return sign;
//
//	}
}<file_sep>/src/main/java/wechat/util/WxPayUtils.java
package wechat.util;

import wechat.constants.ConstantsUtil;
import wechat.pojo.JsAPIConfig;
import wechat.pojo.UnifiedOrder;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

public class WxPayUtils {
	/**
	 * 统一下单
	 *
	 * @Title: unifiedOrder
	 * @Description: TODO
	 * @param: @param openId 微信用户openId
	 * @param: @param order 系统订单信息
	 * @param: @param callbackUrl 回调路径
	 * @param: @return
	 * @param: @throws Exception
	 * @return: String  prepay_id
	 */
//	public static JsAPIConfig unifiedOrder(HttpServletRequest request, String openId, Order order,
//										   String callbackUrl) throws Exception {
//		//[1]创建统一订单对象
//		UnifiedOrder unifiedOrder = new UnifiedOrder();
//		unifiedOrder.setAppid(ConstantsUtil.appid);
//
//		unifiedOrder.setBody("desc");
//		unifiedOrder.setMch_id(ConstantsUtil.mchId);
//
//		String nonce = UUID.randomUUID().toString().replace("-", "").substring(0,32);
//		unifiedOrder.setNonce_str(nonce);
//		unifiedOrder.setNotify_url(callbackUrl);
//
//		unifiedOrder.setOpenid(openId);
//		unifiedOrder.setOut_trade_no(order.getOrdercode());
//
//		//服务器端ip
//		unifiedOrder.setSpbill_create_ip(getRemoteIpAddr(request));
//
//		//测试付款：1分
//		unifiedOrder.setTotal_fee((int)(order.getTotalprice()*100));
//
//		//生成统一订单签名
//		String sign = createSign(unifiedOrder);
//		unifiedOrder.setSign(sign);
//
//		//[2]转化成xml
//		String xml = MessageUtil.messageToXml(unifiedOrder).replace("__", "_");
//
//		System.out.println("统一下单XML："+xml);
//
//		//[3]统一下单，并返回获取prepay_id:
//		String resultXml = httpsRequest(ConstantsUtil.unifiedOrderUrl,xml);
//
//		System.out.println("统一下单返回结果"+resultXml);
//
//		//[4]解析返回数据
//		Map<String,String> resultMap = MessageUtil.parseXml(resultXml);
//
//		if(resultMap.get("return_code").equals("SUCCESS")){
//			//通信成功
//			//System.out.println("通信成功，提示信息："+resultMap.get("return_msg"));
//
//			if(resultMap.get("result_code").equals("SUCCESS")){
//				//统一下单成功,生成JSAPIconfig对象
//				System.out.println("统一下单成功，提示信息："+resultMap.get("return_msg"));
//				return createPayConfig(resultMap,unifiedOrder);
//
//			}else{
//				//统一下单失败
//				//System.out.println("统一下单失败，错误信息："+resultMap.get("return_msg"));
//				JsAPIConfig config = new JsAPIConfig();
//				config.setResult_msg("unifiedOrder_fail");
//				return config;
//			}
//
//		}else
//		{
//			//通信失败
//			//System.out.println("通信失败，错误信息："+resultMap.get("return_msg"));
//			JsAPIConfig config = new JsAPIConfig();
//			config.setResult_msg("unifiedOrder_fail");
//			return config;
//
//		}
//
//
//
//	}

	/**
	 * 生成支付配置
	 * @Title: createPayConfig
	 * @Description: TODO
	 * @param @param preayId 统一下单prepay_id
	 * @param @return
	 * @param @throws Exception
	 * @return JsAPIConfig
	 * @throws
	 */
	public static JsAPIConfig createPayConfig(Map<String,String> resultMap,UnifiedOrder unifiedOrder) throws Exception {
		JsAPIConfig config = new JsAPIConfig();
		config.setResult_msg("SUCCESS");

		String nonce = UUID.randomUUID().toString().replace("-", "").substring(0,32);
		String timestamp = Long.toString(System.currentTimeMillis() / 1000);
		String packageName = "prepay_id="+resultMap.get("prepay_id");

		config.setAppId(ConstantsUtil.appid);
		config.setNonce(nonce);
		config.setTimestamp(timestamp);
		config.setPackageName(packageName);

		String signature = createSignature(config);

		config.setSignature(signature);

		return config;
	}



	//获取客户端真实的IP
	public static String getRemoteIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}


	//生成统一下单sign
	private static String createSign(UnifiedOrder unifiedOrder){
		SortedMap<Object,Object> parameters = new TreeMap<Object,Object>();
		/**
		 * 组装请求参数
		 * 按照ASCII排序
		 */
		parameters.put("appid",unifiedOrder.getAppid());
		parameters.put("body", unifiedOrder.getBody());
		parameters.put("mch_id", unifiedOrder.getMch_id());
		parameters.put("nonce_str", unifiedOrder.getNonce_str());
		parameters.put("out_trade_no", unifiedOrder.getOut_trade_no());
		parameters.put("notify_url", unifiedOrder.getNotify_url());
		parameters.put("spbill_create_ip", unifiedOrder.getSpbill_create_ip());
		parameters.put("total_fee",unifiedOrder.getTotal_fee());
		parameters.put("trade_type",unifiedOrder.getTrade_type());
		parameters.put("openid", unifiedOrder.getOpenid());

		StringBuffer sb = new StringBuffer();
		Set es = parameters.entrySet();//所有参与传参的参数按照accsii排序（升序）
		Iterator it = es.iterator();
		while(it.hasNext()) {
			Map.Entry entry = (Map.Entry)it.next();
			String k = (String)entry.getKey();
			Object v = entry.getValue();
			if(null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
				sb.append(k + "=" + v + "&");
			}
		}
		sb.append("key=" + ConstantsUtil.payKey);
		String sign = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
		return sign;

	}

	//生成调起支付的signature
	private static String createSignature(JsAPIConfig config){
		SortedMap<Object,Object> parameters = new TreeMap<Object,Object>();
		/**
		 * 组装请求参数
		 * 按照ASCII排序
		 */
		parameters.put("appId",ConstantsUtil.appid);
		parameters.put("nonceStr",config.getNonce());
		parameters.put("package", config.getPackageName());
		parameters.put("signType", config.getSignType());
		parameters.put("timeStamp", config.getTimestamp());

		StringBuffer sb = new StringBuffer();
		Set es = parameters.entrySet();//所有参与传参的参数按照accsii排序（升序）
		Iterator it = es.iterator();
		while(it.hasNext()) {
			Map.Entry entry = (Map.Entry)it.next();
			String k = (String)entry.getKey();
			Object v = entry.getValue();
			if(null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
				sb.append(k + "=" + v + "&");
			}
		}
		sb.append("key=" + ConstantsUtil.payKey);
		String signature = MD5Util.MD5Encode(sb.toString(), "UTF-8").toUpperCase();
		return signature;

	}


	public static String httpsRequest(String requestUrl, String xmlStr) {
		try{
			URL url = new URL(requestUrl);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
			connection.setUseCaches(false);
			connection.setRequestMethod("POST");


			OutputStream outputStream = connection.getOutputStream();
			outputStream.write(xmlStr.getBytes("UTF-8"));
			outputStream.close();

			// 从输入流读取返回内容
			InputStream inputStream = connection.getInputStream();
			InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			String str = null;
			StringBuffer buffer = new StringBuffer();
			while ((str = bufferedReader.readLine()) != null) {
				buffer.append(str);
			}
			bufferedReader.close();
			inputStreamReader.close();
			inputStream.close();
			inputStream = null;
			connection.disconnect();
			return buffer.toString();
		}catch(Exception ex){
			ex.printStackTrace();
		}

		return "";
	}


}
<file_sep>/src/main/java/wechat/servlet/JSApiServlet.java
package wechat.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import wechat.constants.ConstantsUtil;
import wechat.util.Sha1Util;
import wechat.util.SignUtil;
import wechat.util.TokenThread;

/**
 * 请求获取Jsapi_ticket，以求在页面上调用微信js
 */
public class JSApiServlet extends HttpServlet {
    private static final long serialVersionUID = 4440739483644821986L;

    /**
     * 请求校验（确认请求来自微信服务器）
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 微信加密签名
        String signature = request.getParameter("signature");
        // 时间戳
        String timestamp = request.getParameter("timestamp");
        // 随机数
        String nonce = request.getParameter("nonce");
        // 随机字符串
        String echostr = request.getParameter("echostr");

        PrintWriter out = response.getWriter();
        // 请求校验，若校验成功则原样返回echostr，表示接入成功，否则接入失败
        if (SignUtil.checkSignature(signature, timestamp, nonce)) {
            out.print(echostr);
        }
        out.close();
        out = null;
    }

    /**
     * 处理微信服务器发来的消息
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 将请求、响应的编码均设置为UTF-8（防止中文乱码）
        request.setCharacterEncoding("UTF-8");
        response.setHeader("Content-type", "text/html;charset=UTF-8");

        getConfig(request, response);
    }

    public void getConfig(HttpServletRequest request,HttpServletResponse response){
        //获取appId
        String appid = ConstantsUtil.appid;

        //获取页面路径(前端获取时采用location.href.split('#')[0]获取url)
        String url = request.getParameter("url");
        //获取access_token
        //String access_token = CommonUtil.getToken(appid, appsecret).getAccessToken();

        //获取ticket
        //String jsapi_ticket = CommonUtil.getJSApiTicket(access_token);
        String jsapi_ticket = TokenThread.jsapiTicket;

        //获取Unix时间戳(java时间戳为13位,所以要截取最后3位,保留前10位)
        String timeStamp = String.valueOf(System.currentTimeMillis()).substring(0, 10);
        //创建有序的Map用于创建签名串
        SortedMap<String, String> params = new TreeMap<String, String>();
        params.put("jsapi_ticket", jsapi_ticket);
        params.put("timestamp", timeStamp);

        String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
        params.put("noncestr", uuid);
        params.put("url", url);

        //签名
        String signature = "";
        try {
            signature = Sha1Util.createSHA1Sign(params);
        }catch (Exception e) {
            e.printStackTrace();
        }
        //得到签名再组装到Map里
        params.put("signature", signature);
        //传入对应的appId
        params.put("appId", appid);
        //组装完毕，回传
        try {
            JSONArray jsonArray = JSONArray.fromObject(params);
            // System.out.println(jsonArray.toString());
            PrintWriter out = response.getWriter();
            out.print(jsonArray);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
<file_sep>/src/main/java/wechat/util/TokenThread.java
package wechat.util;

import wechat.constants.ConstantsUtil;
import wechat.pojo.Token;




/**
 * 线程，获取accessToken
 * 用于保存获取到的access_token和jsapiTicket
 */
public class TokenThread implements Runnable
{
    public static String appid = ConstantsUtil.appid;
    public static String appsecret = ConstantsUtil.appsecret;
    public static Token accessToken = null;
    public static String jsapiTicket = null;

    //两小时运行一次
    public void run()
    {
        while (true)
        {
            try
            {
                //先获取accessToken
                accessToken =CommonUtil.getToken(appid, appsecret);
                System.out.println("获取到accessToken:"+accessToken);
                if (null != accessToken)
                {
                    //通过凭证accessToken调用微信API接口，来获取jsapi的ticket
                    jsapiTicket = CommonUtil.getJSApiTicket(accessToken.getAccessToken());
                    if (null != jsapiTicket)
                    {
                        // 休眠7000秒：如果获取成功，则7000s内不需要在获取
                        System.out.println("获取到jsapiTicket:"+jsapiTicket);
                        Thread.sleep((accessToken.getExpiresIn() - 200) * 1000);
                    }
                    else
                    {
                        //如果获取失败，则60s后再次尝试获取
                        Thread.sleep(60 * 1000);
                    }
                }
                else
                {
                    // 如果access_token为null，60秒后再获取
                    Thread.sleep(60 * 1000);
                }
            }
            catch (InterruptedException e)
            {
                try
                {
                    Thread.sleep(60 * 1000);
                }
                catch (InterruptedException e1)
                {

                }
            }
        }
    }

}
<file_sep>/src/main/java/wechat/servlet/InitServlet.java
package wechat.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import wechat.constants.ConstantsUtil;
import wechat.util.TokenThread;




/**
 * 中控服务器：实现定时获取凭证access_token,在启动的时候实例化并调用其init()方法
 */
public class InitServlet extends HttpServlet
{

    private static final long serialVersionUID = 1L;

    public void init() throws ServletException
    {
        // 未配置APPID、APPSECRET时不启动线程
        if ("".equals(TokenThread.appid) || "".equals(TokenThread.appsecret))
        {
            System.out.println("请先配置appID和appSecret...");
        }
        else
        {
            // 启动定时获取access_token的线程
            new Thread(new TokenThread()).start();
        }

        //加载证书
        ConstantsUtil.certPath = this.getClass().getClassLoader().getResource("apiclient_cert.p12").getPath();
        System.out.println("加载证书路径："+ConstantsUtil.certPath);
    }

}

<file_sep>/src/main/java/com/liyuan/demo/constants/ConstantUtils.java
package com.liyuan.demo.constants;
/**
 * 项目常量类
 * @author Administrator
 *
 */
public class ConstantUtils {
	//项目域名地址
	public static final String serverPath = "http://www.dyjkglass.com/";
	
}
