Wechat official account H5 page custom sharing function, JAVA background signature algorithm implementation, the front end always appears config:invalid signature.

problem description

according to the description of the custom sharing service interface of Wechat"s official account web service, I use access_token to obtain the ticket, backend, and then generate String1, and encrypt it with SHA1 to get the signature signature, and return the signature signature to the frontend based on the timestamp (timestamp), random string (nonceStr) and url (JS API security domain name submitted by the frontend. But when the front end is sharing the page, it always prompts config:invalid signature.. I"m already dizzy. I don"t know what to do with it. Please take a look at the code for me. Thank you.

the environmental background of the problems and what methods you have tried

according to the official document: "after sorting all the parameters to be signed by the ASCII code of the field name from smallest to largest (dictionary order), use the format of URL key-value pairs". I sort the corresponding parameters in ascending order in the server code, and the official account of Wechat will report an error. Later, I saw sandboxie, who was officially provided to generate the signature, and the String1 in it did not sort the parameters in ascending AscII order. I commented out the relevant code and then spliced it directly. As a result, the error was reported. Finally, I directly used the random string and timestamp in sandboxie and the final signature, but still reported an error. I really don"t know what"s going on.

related codes

part of the java code that implements the signature algorithm

import java.security.MessageDigest;

public class WxSignatrueService {

private static final char[] HEX_DIGITS = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };

public static String getWxShareSignatrue(String ticket, String noStr, String url, String timestamp) {
    // char[] _ticket = ticket.toCharArray();
    // char[] _noStr = noStr.toCharArray();
    // char[] _url = url.toCharArray();
    // char[] _timestamp = timestamp.toCharArray();
    //
    // Arrays.sort(_ticket);
    // Arrays.sort(_noStr);
    // Arrays.sort(_url);
    // Arrays.sort(_timestamp);

    // String jsapi_ticket =
    // String.valueOf(_ticket)+"&noncestr="+String.valueOf(_noStr)+"&timestamp="+String.valueOf(_timestamp)+"&url="+_url.toString();

    String jsapi_ticket = "jsapi_ticket=" + ticket + "&noncestr=" + noStr + "&timestamp=" + timestamp + "&url="
            + url;
    
    return new String(encode(jsapi_ticket));
}    

private static String getFormattedText(byte[] bytes) {
    int len = bytes.length;
    StringBuilder buf = new StringBuilder(len * 2);
    // 
    for (int j = 0; j < len; jPP) {
        buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
        buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
    }
    return buf.toString();
}

public static String encode(String str) {
    if (str == null) {
        return null;
    }
    try {
        MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
        messageDigest.update(str.getBytes());
        return getFormattedText(messageDigest.digest());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

}

Front end, on the vue related page, this is how I implement it:

mounted(){
    /* eslint-disable */
    let timestamp = Date.parse(new Date());
    let random = Math.random().toString(36).substr(2);
    let me = this;
    axios.get("https:///getSignature",{params:{noStr:random,url:"",timestamp:timestamp}}).then(res=>{
        wx.config({
            debug:true,
            appId:"appid",
            timestamp:timestamp,
            nonceStr:random,
            signatrue:res.data.data,
            jsApiList:["onMenuShareTimeline","onMenuShareAppMessage"]
        });
        wx.ready(function(){
            wx.onMenuShareTimeline({
                title:"",
                link:"",
                imgUrl:""+me.backUrl,
                success:function(){

                }
            });
            wx.onMenuShareAppMessage({
                title:"",
                desc:"",
                link:"/eaglepublic",
                imgUrl:""+me.backUrl,
                success:function(){

                }
            })
        })

    })

what result do you expect? What is the error message actually seen?

I look forward to seeing the icon when sharing my page with friends or moments, and don"t prompt for that error, and access the link address I specified.
which experienced god can help me solve this problem?


is the signed url address the same as the url address you want to share?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e83bf9-c7d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e83bf9-c7d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?