微信公众号测试号配置java版-jfinal

原文地址:https://blog.csdn.net/mzmzo/article/details/50991616
package com.javen.weixin.controller;

import java.security.MessageDigest;
import java.util.Arrays;
import org.apache.commons.codec.binary.Hex;
import com.jfinal.core.Controller;

public class TestWeixinController extends Controller{
	public void index() throws Exception{
		// 开发者提交信息后,微信服务器将发送GET请求到填写的服务器地址URL上,GET请求携带参数  
        String signature = getPara("signature");// 微信加密签名(token、timestamp、nonce。)  
        String timestamp = getPara("timestamp");// 时间戳  
        String nonce = getPara("nonce");// 随机数  
        String echostr = getPara("echostr");// 随机字符串  
        //PrintWriter out = response.getWriter();  
        // 将token、timestamp、nonce三个参数进行字典序排序  
        String[] params = new String[] { "yourToken", timestamp, nonce };  
        Arrays.sort(params);  
        // 将三个参数字符串拼接成一个字符串进行sha1加密  
        String clearText = params[0] + params[1] + params[2];  
        String algorithm = "SHA-1";  
        String sign = new String(  
                Hex.encodeHex(MessageDigest.getInstance(algorithm).digest((clearText).getBytes()), true));  
        // 开发者获得加密后的字符串可与signature对比,标识该请求来源于微信  
        if (signature.equals(sign)) {  
            //response.getWriter().print(echostr);  
        	renderJson(echostr);
        } 
	}
}

 

 

原文地址:https://blog.csdn.net/mzmzo/article/details/50991616

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值