Search in sources :

Example 1 with WxJsapiSignature

use of me.chanjar.weixin.common.bean.WxJsapiSignature in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method createJsapiSignature.

public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
    long timestamp = System.currentTimeMillis() / 1000;
    String noncestr = RandomUtils.getRandomStr();
    String jsapiTicket = getJsapiTicket(false);
    try {
        String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url);
        WxJsapiSignature jsapiSignature = new WxJsapiSignature();
        jsapiSignature.setTimestamp(timestamp);
        jsapiSignature.setNoncestr(noncestr);
        jsapiSignature.setUrl(url);
        jsapiSignature.setSignature(signature);
        return jsapiSignature;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}
Also used : WxJsapiSignature(me.chanjar.weixin.common.bean.WxJsapiSignature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with WxJsapiSignature

use of me.chanjar.weixin.common.bean.WxJsapiSignature in project weixin-java-tools by chanjarster.

the class WxMpServiceImpl method createJsapiSignature.

public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException {
    long timestamp = System.currentTimeMillis() / 1000;
    String noncestr = RandomUtils.getRandomStr();
    String jsapiTicket = getJsapiTicket(false);
    try {
        String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket, "noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url);
        WxJsapiSignature jsapiSignature = new WxJsapiSignature();
        jsapiSignature.setAppid(wxMpConfigStorage.getAppId());
        jsapiSignature.setTimestamp(timestamp);
        jsapiSignature.setNoncestr(noncestr);
        jsapiSignature.setUrl(url);
        jsapiSignature.setSignature(signature);
        return jsapiSignature;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}
Also used : WxJsapiSignature(me.chanjar.weixin.common.bean.WxJsapiSignature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 WxJsapiSignature (me.chanjar.weixin.common.bean.WxJsapiSignature)2