package com.offcn.TestUnti;



import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;


/**
 * 魔蝎验签
 * @author puhui
 *
 */
public class MoXie {

	public static void main(String[] args) {
		String s="{\"mobile\":\"13910960649\",\"user_id\":\"d9c3a0add4d545fbb236f25671e189ed-order\",\"task_id\":\"12345\",\"name\":\"姚帅\",\"idcard\":\"11022119811222061X\",\"result\":\"true\",\"message\":\"报告通知\",\"timestamp\":3000}";
		System.out.println(MoXie.base64Hmac256(s, "27c7e4bc518c48d095d9caf544771876"));
	}
	public static String base64Hmac256(String payload, String secret) {
	    try {
	        Mac sha256Hmac = Mac.getInstance("HmacSHA256");
	        SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
	        sha256Hmac.init(secretKey);
	        return Base64.encodeBase64String(sha256Hmac.doFinal(payload.getBytes()));
	    } catch (Exception ignored) {
	        return "";
	    }
	}
	public static String jiaFanXieXian(String str){
		str=str.replaceAll("\"", "\\\"");
		return str;
	}
	
}
