You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.9 KiB
63 lines
2.9 KiB
package com.hfkj.jd;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.hfkj.common.utils.HttpsUtils;
|
|
import com.hfkj.common.utils.RsaCoderUtils;
|
|
import com.hfkj.config.CommonSysConst;
|
|
import com.hfkj.meituan.MeiTuanService;
|
|
import com.jd.open.api.sdk.DefaultJdClient;
|
|
import com.jd.open.api.sdk.JdClient;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.net.URLEncoder;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @ClassName JdService
|
|
* @Author Sum1Dream
|
|
* @Description 京东服务
|
|
* @Date 2024/10/11 下午3:25
|
|
**/
|
|
public class JdService {
|
|
private static Logger log = LoggerFactory.getLogger(JdService.class);
|
|
|
|
/**
|
|
* UTF_8
|
|
*/
|
|
public static final String UTF_8 = "utf-8";
|
|
/**
|
|
* 用户名
|
|
*/
|
|
private static final String USERNAME = "惠兑重庆VOP",
|
|
/**
|
|
* 明文密码,后续需要通过RSA加密
|
|
*/
|
|
PLAINTEXT_PASSWORD = "hdcs1234",
|
|
/**
|
|
* 回调地址,注册应用时配置的授权回调地址
|
|
*/
|
|
REDIRECT_URI = CommonSysConst.getSysConfig().getDomainName() + "/order/jdNotify/callbackToken",
|
|
/**
|
|
* RSA私钥
|
|
*/
|
|
PRIVATE_RSA_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMEtt0kF02YBxPXzXyqzCtr1zkuj8NXLiqqSCDAfU6zWB1T1GUEpCfNukPBeZ9nXGj+jbTom8RFllNXbnOkW01Zn2VoyePh8TRWQbToXi+i/JQ162GzpF0GdPsUhJSrB5Z2QzK4UVXXkpPHhQHR8NKQhvTRkoRLfOy+oXWL8PS2hAgMBAAECgYBySo/j/jRiZ62WLlUhuCg1/7P8AJSeiPwTiq6Zeg9RdJeF5jT43kTq54GNFO2wbpkzCYe4Hg4GUulJ1dLx/PUvYquRpM4jGznxDxBA10mNyjx0O+SHcY+ZlOYWIKhEq4MeeJhtHhoFrlgcMNIyofhRDbFzrRak48GrcZDQC4/cIQJBAPwxtEwMnetPveLExR1UsygdVKwoWoGNL5Hkhcx6b2N2Qapk5aHB5haUEXeg1ShrL4C/kE1lsMAIdpVS9lWd4x0CQQDEGASnnB2oPHjvNfj88klpYTvPJRi3ORQPtlfz36kv+29QFxB9Mt1u39ttopw5G2x7QvTtL542w878brrmS8lVAkEA4k7QFjZ0N8cVBLvCjrGFG4hGhT6pCPxjJa5GCtoLvttNzdRA5EkVaklw60LeRSj6NbSxj2Kjm498qj8KYoYOWQJATJhRISMy1mcgmdeMNUlycW4gjY4g9FigRG7mNgU0MeDVnwQTVcQLiGZ6cH2m5guXOSJzRz5lX2DmteWOrawGrQJBAMKLfeTnYkVpXw9MABcR/9L9myG3FKwOHBIqD0wK+QVahi9byFk8GFXD4OlBQ1ZSxHqsUuxWqLVSa3sWBCKpLo8=";
|
|
|
|
public static JSONObject getAccessToken() throws Exception {
|
|
String encodeRedirectUri = URLEncoder.encode(REDIRECT_URI, UTF_8);
|
|
String encodeUsername = URLEncoder.encode(USERNAME, UTF_8);
|
|
String md5Password = DigestUtils.md5Hex(PLAINTEXT_PASSWORD);
|
|
String ciphertextPassword = RsaCoderUtils.encryptByPrivateKey(md5Password, PRIVATE_RSA_KEY);
|
|
String encodePassword = URLEncoder.encode(ciphertextPassword, UTF_8);
|
|
|
|
JSONObject object = new JSONObject();
|
|
object.put("app_key", CommonSysConst.getSysConfig().getJDAppKey());
|
|
object.put("redirect_uri", encodeRedirectUri);
|
|
object.put("username", encodeUsername);
|
|
object.put("password", encodePassword);
|
|
object.put("response_type", "code");
|
|
object.put("scope", "snsapi_base");
|
|
return HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/authorizeForVOP", object);
|
|
}
|
|
}
|
|
|