E-commerce platform capability interface
E-commerce service provider interface verification signature
//Here are the parameters when calling the interface $data_ list = ["goods_id"=>"371965", "appid"=> 100023, "sign_type"=>"md5"]; //This is the signature secret key of e-commerce, which can be obtained by contacting the microblog e-commerce platform $key = 'YOUR SIGN KEY'; //Start generating signatures and outputting signatures echo getSign($data_list, $key); //Obtain signature according to algorithm public static function getSign($data_list, $key, $filter_k_list = ["sign", "sign_type", "access_token",], $filter_v_list = ["",]) { //Filter parameters not participating in signature foreach ($data_list as $k => $v) { if (in_array($k, $filter_k_list, true) || in_ array($v, $filter_v_list, true)) { unset($data_list[$k]); } } //Sort ksort($data_list); //Convert to query string, pay attention to the space before and after filtering $parameter = []; foreach ($data_list as $k => $v) { $parameter[] = $k . "=" . trim($v); } $string = implode("&", $parameter); //Splicing key $stringKey = $string . $ key; //Perform MD5 to get the final signature $sign = md5($stringKey); return $sign; }
import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; class Sign { public static final String[] filterKeys = new String[]{"sign", "sign_type", "access_token"}; public static void main(String[] args) { Map<String, String> dataList = new HashMap<>(); //Here are the parameters when calling the interface dataList.put("goods_id", "371965"); dataList.put("appid", "100023"); dataList.put("sign_type", "md5"); //This is the signature secret key of e-commerce, which can be obtained by contacting the microblog e-commerce platform String secret = "YOUR SIGN KEY"; //Start generating signature String sign = getSign(dataList, secret); //Output Signature System.out.println(sign); } //Obtain signature according to algorithm public static String getSign(Map<String, String> dataList, String secret) { Set<String> keySet = dataList.keySet(); String[] keyArray = keySet.toArray(new String[0]); Arrays.sort(keyArray); StringBuilder sb = new StringBuilder(); String prefix = ""; for (int i = 0; i < keyArray.length; i++) { if (Arrays.asList(filterKeys).contains(keyArray[i])) { continue; } sb.append(prefix).append(keyArray[i]).append("=").append(dataList.get(keyArray[i])); prefix = "&"; } sb.append(secret); return md5(sb.toString()); } public static String md5(String input) { try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] messageDigest = md.digest(input.getBytes()); BigInteger no = new BigInteger(1, messageDigest); String hashtext = no.toString(16); while (hashtext.length() < 32) { hashtext = "0" + hashtext; } return hashtext; } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } }
package main import ( "crypto/md5" "encoding/hex" "fmt" "sort" ) func main() { //Here are the parameters when calling the interface dataList := map[string]string{"goods_id": "371965", "appid": "100023", "sign_type": "md5"} //This is the signature secret key of e-commerce, which can be obtained by contacting the microblog e-commerce platform secret := "YOUR SIGN KEY" //Start generating signature sign := getSign(dataList, secret) //Output Signature fmt. Println(sign) } //Obtain signature according to algorithm func getSign(dataList map[string]string, secret string) string { var keys []string prefix := "" str := "" //Filter parameters not participating in signature filterKList := [3]string{"sign", "sign_type", "access_token"} for k := range dataList { keys = append(keys, k) } //Sort sort.Strings(keys) //Convert to query string, pay attention to the space before and after filtering for _, k := range keys { flag := false for _, filterK := range filterKList { if k == filterK { flag = true break } } if ! flag { str += prefix + k + "=" + dataList[k] prefix = "&" } } //Splicing key str += secret //Perform MD5 to get the final signature h := md5.New() h.Write([]byte(str)) return hex. EncodeToString(h.Sum(nil)) }
Order capability interface
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Commodity capability interface
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Event notification push
appendix