• 钉钉扫码登录第三方,appSecret签名算法(附包名)


    包名

    import java.io.UnsupportedEncodingException;
    import java.net.URLEncoder;
    import javax.crypto.Mac;
    import javax.crypto.spec.SecretKeySpec;
    import org.apache.commons.codec.binary.Base64;
    

    方法

    /**
     * 1免登 - 通过appSecret计算出来的签名值,并进行urlEncode
     * 1签名算法为
     * */
    public static String getAppSecretSign(String appSecret, String timestamp) {
    	String signStr = "";
    	// 根据timestamp, appSecret计算签名值
    	try {
    		
    		String stringToSign = timestamp;
    		Mac mac = Mac.getInstance("HmacSHA256");
    		mac.init(new SecretKeySpec(appSecret.getBytes("UTF-8"), "HmacSHA256"));
    		byte[] signatureBytes = mac.doFinal(stringToSign.getBytes("UTF-8"));
    		String signature = new String(Base64.encodeBase64(signatureBytes));
    		signStr = urlEncode(signature,"UTF-8");
    	} catch (Exception e) {
    		e.printStackTrace();
    	} finally {
    		
    	}
    	return signStr;
    }
    
     /**
     * 1钉钉免登签名算法 - urlEncode
     * 
     * */
    public static String urlEncode(String value, String encoding) {
        if (value == null) {
            return "";
        }
        try {
            String encoded = URLEncoder.encode(value, encoding);
            return encoded.replace("+", "%20").replace("*", "%2A")
                .replace("~", "%7E").replace("/", "%2F");
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException("FailedToEncodeUri", e);
        }
    }
  • 相关阅读:
    TweenMax参数补充
    jQuery.lazyload详解
    js函数和jquery函数详解
    数数苹果手机中的不科学
    网页全栈工程师要点分析
    瞄了一眼墙外的世界,只能给差评
    脑洞大开的自然语言验证码
    别再迷信 zepto 了
    产品列表页分类筛选、排序的算法实现(PHP)
    大学回顾和C与PHP之路
  • 原文地址:https://www.cnblogs.com/qungmu/p/12682136.html
Copyright © 2020-2023  润新知