日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

拼多多商品推广转链

發布時間:2023/12/20 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 拼多多商品推广转链 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

平多多平臺接入文檔?http://open.pinduoduo.com/#/document
API文檔:?http://open.pinduoduo.com/#/apidocument

所有的API都需要‘簽名’

image

簽名工具類:

import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Component;import javax.servlet.http.HttpServletRequest; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Enumeration; import java.util.Map; import java.util.TreeMap;/*** @author MkStone slinstone@163.com* @date 2018/6/17 21:35*/ @Component public class MD5_Sign {public static String client_id="你的 client_id";public static String client_secret="你的client_secret";public static String md5(String string) {byte[] hash;try {hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8"));} catch (UnsupportedEncodingException e) {throw new RuntimeException("UTF-8 is unsupported", e);} catch (NoSuchAlgorithmException e) {throw new RuntimeException("MessageDigest不支持MD5Util", e);}StringBuilder hex = new StringBuilder(hash.length * 2);for (byte b : hash) {if ((b & 0xFF) < 0x10) hex.append("0");hex.append(Integer.toHexString(b & 0xFF));}return hex.toString();}/*** md5簽名** 按參數名稱升序,將參數值進行連接 簽名* @param params* @return*/public static String sign( TreeMap<String, String> params) {StringBuilder paramValues = new StringBuilder();params.put("client_id", client_id);for (Map.Entry<String, String> entry : params.entrySet()) {paramValues.append(entry.getKey()+entry.getValue());}/* //拼多多 簽名認證*簽名算法POP目前支持的簽名算法為:MD5(sign_method=md5),簽名大體過程如下:1-所有參數進行按照首字母先后順序排列2-把排序后的結果按照參數名+參數值的方式拼接3-拼裝好的字符串首尾拼接client_secret進行md5加密后轉大寫,secret的值是拼多多開放平臺后臺分配的client_secret** */System.out.println(client_secret+paramValues.toString()+client_secret);String Md5Sign=md5(client_secret+paramValues.toString()+client_secret).toUpperCase();System.out.println(Md5Sign);return Md5Sign;}/*** 請求參數簽名驗證** @param request* @return true 驗證通過 false 驗證失敗* @throws Exception*/public static boolean verifySign(HttpServletRequest request) throws Exception {TreeMap<String, String> params = new TreeMap<String, String>();String signStr = request.getParameter("sign");if(StringUtils.isBlank(signStr)){throw new RuntimeException("There is no signature field in the request parameter!");}Enumeration<String> enu = request.getParameterNames();while (enu.hasMoreElements()) {String paramName = enu.nextElement().trim();if (!paramName.equals("sign")) {params.put(paramName, URLDecoder.decode(request.getParameter(paramName), "UTF-8"));}}if (!sign(params).equals(signStr)) {return false;}return true;}

如何使用?

//簽名String sign="";TreeMap<String,String> map=new TreeMap<String, String>();//商品map.put("goods_id_list","["+GoodsId+"]");map.put("type",type);map.put("p_id",pid);map.put("generate_short_url","true");map.put("data_type","JSON");map.put("timestamp",timestam);sign = MD5_Sign.sign(map);

多多客商品轉鏈 ddk_link(id,GoodsId);

public String ddk_link(String pid,String GoodsId){String url="http://gw-api.pinduoduo.com/api/router?";//參數String timestam=(new Date().getTime()/1000)+"";String sign="";TreeMap<String,String> map=new TreeMap<String, String>();//商品map.put("goods_id_list","["+GoodsId+"]");map.put("type",type);map.put("p_id",pid);map.put("generate_short_url","true");map.put("data_type","JSON");map.put("timestamp",timestam);sign = MD5_Sign.sign(map);//type 值url+="type="+type;// 返回值類型url+="&data_type=JSON";//ClienmtIDurl+="&client_id="+client_id;//商品IDurl+="&goods_id_list=["+GoodsId+"]";//推廣位IDurl+="&p_id="+pid;// 是否生成短鏈接,true-是,false-否url+="&generate_short_url=true";url+="&timestamp="+timestam;url+="&sign="+sign;return loadJSON(url);}public String loadJSON (String url) {StringBuilder json = new StringBuilder();try {URL oracle = new URL(url);HttpURLConnection connection = (HttpURLConnection) oracle.openConnection();connection.setDoOutput(true);connection.setDoInput(true);connection.setUseCaches(false);connection.setInstanceFollowRedirects(true);connection.setRequestMethod("POST"); // 設置請求方式connection.setRequestProperty("Accept", "application/json"); // 設置接收數據的格式connection.connect();BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));String inputLine = null;while ( (inputLine = in.readLine()) != null) {json.append(inputLine);}in.close();} catch (IOException e) {return "-1";}return json.toString();}

總結

以上是生活随笔為你收集整理的拼多多商品推广转链的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。