Skip to content

Commit

Permalink
Merge pull request #110 from hocgin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
hocgin committed Nov 5, 2022
2 parents 412cd90 + cce7c8a commit c2377a4
Show file tree
Hide file tree
Showing 51 changed files with 1,286 additions and 115 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<module>spring-boot-ws</module>
<module>spring-boot-notify</module>
<module>spring-boot-kafka</module>
<module>spring-boot-cps</module>
<module>spring-boot-tpl</module>
</modules>

Expand Down
23 changes: 23 additions & 0 deletions spring-boot-cps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- https://www.kancloud.cn/weixinsdk/taobaoke_pid/3036718
- http://www.wlkankan.cn/cate49/293.html
- http://wxmp.sharepay.xyz/index 13600747016 / qwert12345x
- https://www.huochangliang.com/2020/06/33351
- https://www.dataoke.com/kfpt/apply-d.html?id=33245

### 京东联盟ID / 京东Key
- https://union.jd.com/user
- https://union.jd.com/myTools/myApi

### 拼多多
- https://jinbao.pinduoduo.com/external/open?client_id=8396b8db8aa74676bee7db57d86ef54a&response_type=code&state=7197227421&redirect_uri=

### 淘宝
- https://console.open.taobao.com/?spm=a219a.7395903.0.0.628e3172aUZDfD#/index
- https://pub.alimama.com/third/manage/record/site.htm
- API.DOC: https://developer.alibaba.com/docs/api.htm?apiId=31127
#### 淘宝的 PID、site_id、 adzone_id

https://www.dingdanxia.com/article/5.html

#### 淘宝的 Good Id
https://item.taobao.com/item.htm?id=665636198500
90 changes: 90 additions & 0 deletions spring-boot-cps/cps-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-boot-cps</artifactId>
<groupId>in.hocg.boot</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>

<name>CPS :: Spring Boot :: AutoConfigure</name>
<artifactId>cps-spring-boot-autoconfigure</artifactId>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
<!-- 淘宝 -->
<dependency>
<groupId>com.cps.tb</groupId>
<artifactId>taobao-sdk</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/tb/taobao-sdk-java-auto_1603790307338-20221010.jar
</systemPath>
</dependency>
<!-- 唯品会 -->
<dependency>
<groupId>com.cps.wph</groupId>
<artifactId>osp-sdk</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/wph/osp-sdk.jar</systemPath>
</dependency>
<dependency>
<groupId>com.cps.wph</groupId>
<artifactId>vop-sdk</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/wph/vop-sdk.jar</systemPath>
</dependency>
<!-- 蘑菇街 -->
<dependency>
<groupId>com.cps.mgj</groupId>
<artifactId>openapi-sdk</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/mgj/sdk/openapi-sdk.jar</systemPath>
</dependency>
<!-- 拼多多 -->
<dependency>
<groupId>com.cps.pdd</groupId>
<artifactId>pop-sdk-all</artifactId>
<classifier>all</classifier>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/pdd/sdk/pop-sdk-1.10.53-all.jar</systemPath>
</dependency>
<!-- 其他 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<optional>true</optional>
</dependency>
<!-- Basic -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>utils-base</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package in.hocg.boot.cps.autoconfiguration;

import in.hocg.boot.cps.autoconfiguration.impl.CpsBervice;
import in.hocg.boot.cps.autoconfiguration.impl.dataoke.DaTaoKeBerviceImpl;
import in.hocg.boot.cps.autoconfiguration.properties.CpsProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
* Created by hocgin on 2020/8/15
* email: hocgin@gmail.com
*
* @author hocgin
*/
@Configuration
@ConditionalOnProperty(prefix = CpsProperties.PREFIX, name = "enabled", matchIfMissing = true)
@EnableConfigurationProperties(CpsProperties.class)
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class CpsAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public CpsBervice cpsBervice(CpsProperties properties) {
if (CpsProperties.Type.DaTaoKe.equals(properties.getType())) {
return new DaTaoKeBerviceImpl(properties.getDaTaoKe());
}
throw new UnsupportedOperationException();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package in.hocg.boot.cps.autoconfiguration.enums;

import in.hocg.boot.utils.enums.ICode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.io.Serializable;

/**
* @author hocgin
*/
@Getter
@RequiredArgsConstructor
public enum PlatformType implements ICode {
TaoBao("taobao", "淘宝"),
Jd("jd", "京东"),
Pdd("pdd", "拼多多"),
;
private final Serializable code;
private final String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package in.hocg.boot.cps.autoconfiguration.impl;

import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.StrUtil;
import in.hocg.boot.cps.autoconfiguration.enums.PlatformType;
import in.hocg.boot.cps.autoconfiguration.pojo.vo.PrivilegeLinkVo;
import in.hocg.boot.utils.LangUtils;

import java.util.Map;
import java.util.Optional;

public interface CpsBervice {

PrivilegeLinkVo getPrivilegeLink(PlatformType type, String goodId);

default Optional<PrivilegeLinkVo> getPrivilegeLink(String url) {
PrivilegeLinkVo result = null;
if (StrUtil.contains(url, "taobao.com") || StrUtil.contains(url, "tmall.com")) {
Pair<String, Map<String, String>> urlParams = LangUtils.getParams(url);
Map<String, String> params = urlParams.getValue();
String id = StrUtil.blankToDefault(params.get("id"), params.get("x-itemid"));
result = getPrivilegeLink(PlatformType.TaoBao, id);
} else if (StrUtil.contains(url, "jd.com")) {
result = getPrivilegeLink(PlatformType.Jd, url);
}
return Optional.ofNullable(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package in.hocg.boot.cps.autoconfiguration.impl.dataoke;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import in.hocg.boot.cps.autoconfiguration.enums.PlatformType;
import in.hocg.boot.cps.autoconfiguration.impl.CpsBervice;
import in.hocg.boot.cps.autoconfiguration.impl.dataoke.lib.ApiClient;
import in.hocg.boot.cps.autoconfiguration.pojo.vo.PrivilegeLinkVo;
import in.hocg.boot.cps.autoconfiguration.properties.CpsProperties;
import in.hocg.boot.utils.LangUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;

import java.util.TreeMap;

/**
* @author hocgin
*/
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Lazy))
public class DaTaoKeBerviceImpl implements CpsBervice {
private final CpsProperties.DaTaoKeConfig config;

@Override
public PrivilegeLinkVo getPrivilegeLink(PlatformType type, String goodId) {
if (PlatformType.TaoBao.anyMatch(type.getCode())) {
return getPrivilegeLinkByTaoBao(goodId);
} else if (PlatformType.Jd.anyMatch(type.getCode())) {
return getPrivilegeLinkByJd(config.getJdUnionId(), goodId);
} else if (PlatformType.Pdd.anyMatch(type.getCode())) {
return getPrivilegeLinkByPdd(goodId);
}
return null;
}

private PrivilegeLinkVo getPrivilegeLinkByPdd(String goodId) {
TreeMap<String, String> paraMap = new TreeMap<>();
paraMap.put("appKey", config.getAppKey());
paraMap.put("version", "v1.0.0");
paraMap.put("goodsSign", goodId);
String data = ApiClient.sendReq("https://openapi.dataoke.com/api/dels/pdd/kit/goods-prom-generate", config.getSecret(), paraMap);
PrivilegeLinkVo result = new PrivilegeLinkVo();
result.setPrivilegeUrl(ObjectUtil.defaultIfBlank(StrUtil.toString(JSONUtil.getByPath(JSONUtil.parse(data), "data.shortUrl")), null));
return result;
}

private PrivilegeLinkVo getPrivilegeLinkByJd(String unionId, String materialId) {
TreeMap<String, String> paraMap = new TreeMap<>();
paraMap.put("appKey", config.getAppKey());
paraMap.put("version", "v1.0.0");
paraMap.put("unionId", unionId);
paraMap.put("materialId", materialId);
String data = ApiClient.sendReq("https://openapi.dataoke.com/api/dels/jd/kit/promotion-union-convert", config.getSecret(), paraMap);
PrivilegeLinkVo result = new PrivilegeLinkVo();
String privilegeUrl = ObjectUtil.defaultIfBlank(StrUtil.toString(JSONUtil.getByPath(JSONUtil.parse(data), "data.shortUrl")), null);
String shortCode = LangUtils.lastElement(StrUtil.split(privilegeUrl, "/"));
String content = HttpUtil.get(privilegeUrl);
String jbaUrl = LangUtils.extract(StrUtil.format("https\\://u\\.jd\\.com/jda.*?{}", shortCode), content);
String location = HttpUtil.createGet(jbaUrl).setFollowRedirects(false).execute().header("location");
// location = https://item.m.jd.com/product/10035254492755.html?cu=true&utm_source=kong&utm_medium=jingfen&utm_campaign=t_1003815318_0a0a0a0a0&utm_term=72f4444ec290409eba12e651f7c2a4b4
location = StrUtil.replace(location, "/product/", "/")
.replace(".m.", ".");
result.setPrivilegeUrl(location);
return result;
}


private PrivilegeLinkVo getPrivilegeLinkByTaoBao(String goodId) {
TreeMap<String, String> paraMap = new TreeMap<>();
paraMap.put("appKey", config.getAppKey());
paraMap.put("version", "v1.3.1");
paraMap.put("goodsId", goodId);
String data = ApiClient.sendReq("https://openapi.dataoke.com/api/tb-service/get-privilege-link", config.getSecret(), paraMap);
PrivilegeLinkVo result = new PrivilegeLinkVo();
String privilegeUrl = ObjectUtil.defaultIfBlank(StrUtil.toString(JSONUtil.getByPath(JSONUtil.parse(data), "data.itemUrl")), null);
result.setPrivilegeUrl(privilegeUrl);
return result;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package in.hocg.boot.cps.autoconfiguration.impl.dataoke.lib;

import java.net.URISyntaxException;
import java.util.TreeMap;

/**
* @projectName:dtk-items-openapi
* @createTime: 2019年11月28日14:13:21
* @description:
*/
public class ApiClient {

public static String sendReqNew(String url, String secret, TreeMap<String, String> paraMap) {
if (null == url || "".equals(url)) {
return "请求地址不能为空";
}
if (null == secret || "".equals(secret)) {
return "secret不能为空";
}
if (null == paraMap || paraMap.size() < 1) {
return "参数不能为空";
}

String timer = String.valueOf(System.currentTimeMillis());
paraMap.put("timer", timer);
paraMap.put("nonce", "110505");
paraMap.put("signRan", SignMD5Util.getSignStrNew(paraMap, secret));
String data = "";
try {
data = HttpUtil.httpGetRequest(url, paraMap);
} catch (URISyntaxException e) {
e.printStackTrace();
}

return data;
}

public static String sendReq(String url, String secret, TreeMap<String, String> paraMap) {
if (null == url || "".equals(url)) {
return "请求地址不能为空";
}
if (null == secret || "".equals(secret)) {
return "secret不能为空";
}
if (null == paraMap || paraMap.size() < 1) {
return "参数不能为空";
}

paraMap.put("sign", SignMD5Util.getSignStr(paraMap, secret));
String data = "";
try {
data = HttpUtil.httpGetRequest(url, paraMap);
} catch (URISyntaxException e) {
e.printStackTrace();
}

return data;
}

}

0 comments on commit c2377a4

Please sign in to comment.