.....
This commit is contained in:
parent
e5f05825de
commit
21bbaa9b1f
@ -1,13 +1,21 @@
|
||||
package com.szxgl.nft;
|
||||
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
||||
|
||||
@SpringBootApplication
|
||||
public class NftApplication {
|
||||
public class NftApplication extends SpringBootServletInitializer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NftApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
||||
return builder.sources(NftApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.szxgl.nft.entity.UserNftPhoto;
|
||||
import com.szxgl.nft.exception.ParameterException;
|
||||
import com.szxgl.nft.service.NftPhotoService;
|
||||
import com.szxgl.nft.service.UserService;
|
||||
import com.szxgl.nft.utils.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -23,67 +24,87 @@ public class NFTPhotoController {
|
||||
@Autowired
|
||||
private NftPhotoService nftPhotoService;
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 获取entropy
|
||||
* @param seed 手机号 随机获取图片hash值 select id from nft_photo where LENGTH(phone) = 0 and `status` = 1 order by rand() LIMIT 1
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getEntropy")
|
||||
public R getEntropy(String seed){
|
||||
|
||||
public R getEntropy(String seed,HttpServletRequest request){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
if(StringUtils.isBlank(seed)){
|
||||
log.error("seed不能为空:"+seed);
|
||||
return R.error("手机号不能为空");
|
||||
}
|
||||
|
||||
//查询用户通过手机是否绑定Nft图片
|
||||
UserNftPhoto userNftPhoto = nftPhotoService.getNftPhoto(seed);
|
||||
if(userNftPhoto == null ){
|
||||
if(userNftPhoto != null ){
|
||||
//手机号加密
|
||||
String phone = encrypt(seed);
|
||||
phone = String.format("{'phone':'%s'}",phone);
|
||||
phone = String.format("{'seed':'%s'}",phone);
|
||||
JSONObject jsonObject = JSONObject.parseObject(phone);
|
||||
System.out.println(jsonObject);
|
||||
//调用第三方接口
|
||||
JSONObject json = HttpClientUtil.doPost("", jsonObject);
|
||||
JSONObject json = HttpClientUtils.httpPost("https://stg-nft-gallery.pingan.com.cn/PABankNewsConference/entropy", jsonObject);
|
||||
if(!"SUCCESS".equals(json.get("code"))){
|
||||
log.error( "获取entropy失败!json:"+json);
|
||||
return R.error("获取entropy失败!");
|
||||
}
|
||||
return R.ok(json);
|
||||
}else {
|
||||
return R.error("手机号没有领取NFT图片资格,获取entropy失败!");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取数字产品
|
||||
* @param seed
|
||||
* @param walletAddr
|
||||
* @param paintingHash
|
||||
* 领取数字藏品
|
||||
* @param walletAddr 钱包地址
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/addNFTs")
|
||||
public R addNFTs(String seed,String walletAddr,String paintingHash){
|
||||
public R addNFTs(String walletAddr,HttpServletRequest request,String nickname){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
if(StringUtils.isBlank(walletAddr)){
|
||||
log.error("walletAddr不能为空:"+walletAddr);
|
||||
throw new ParameterException("walletAddr不能为空");
|
||||
}else if(StringUtils.isBlank(paintingHash)){
|
||||
log.error("paintingHash:"+paintingHash);
|
||||
throw new ParameterException("paintingHash不能为空");
|
||||
return R.error("walletAddr不能为空");
|
||||
}
|
||||
String format = String.format("{'walletAddr':'%s','':'paintingHash'%s}", walletAddr, paintingHash);
|
||||
//获取用户的手机号和图片hash值
|
||||
Map<String,Object> map = nftPhotoService.getPhoneAndHash(openid);
|
||||
String format = String.format("{'seed':'%s','walletAddr':'%s','paintingHash':'%s','message':'%s'}",map.get("phone"),walletAddr, map.get("painting_hash"),nickname);
|
||||
System.out.println(format);
|
||||
JSONObject jsonObject = JSONObject.parseObject(format);
|
||||
JSONObject json = HttpClientUtil.doPost("", jsonObject);
|
||||
|
||||
JSONObject json = HttpClientUtils.httpPost("https://stg-nft-gallery.pingan.com.cn/PABankNewsConference/nfts", jsonObject);
|
||||
//第三方备份用户和NFT图片对应关系操作成功
|
||||
if("SUCCESS".equals(json.get("code"))){
|
||||
//绑定用户昵称
|
||||
userService.addUserNftPhoto(openid,nickname,walletAddr);
|
||||
}
|
||||
return R.ok(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取数字产品展示页面
|
||||
* 领取数字藏品展示页面
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getNftPhoto")
|
||||
public R getNftPhoto(String openid,HttpServletRequest request){
|
||||
// String openid = CookieUtil.getCookie(request.getCookies());
|
||||
// if(StringUtils.isBlank(openid)){
|
||||
// log.error("openid为空:"+openid);
|
||||
// throw new ParameterException("openid为空");
|
||||
// }
|
||||
public R getNftPhoto(HttpServletRequest request){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
Map<String, Object> map = nftPhotoService.getNftPhotoUrl(openid);
|
||||
int status = (int)map.get("status");
|
||||
String name = (String) map.get("name");
|
||||
@ -114,10 +135,11 @@ public class NFTPhotoController {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String format = String.format("{'walletAddr':'%s','paintingHash':'%s'}", "walletAddr", "paintingHash");
|
||||
String format = String.format("{'seed':'%s','walletAddr':'%s','paintingHash':'%s','message':''}","seed", "walletAddr", "paintingHash");
|
||||
JSONObject jsonObject = JSONObject.parseObject(format);
|
||||
System.out.println(jsonObject);
|
||||
//cdn访问路径:https://cdn.xglpa.com/pars-nft/directional200/0306chunfen_29_1583466279_0000519.png
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,8 +2,10 @@ package com.szxgl.nft.controller;
|
||||
|
||||
import com.szxgl.nft.entity.RedisKeyName;
|
||||
import com.szxgl.nft.entity.UserDO;
|
||||
import com.szxgl.nft.exception.ParameterException;
|
||||
import com.szxgl.nft.service.NftPhotoService;
|
||||
import com.szxgl.nft.service.UserService;
|
||||
import com.szxgl.nft.utils.CookieUtil;
|
||||
import com.szxgl.nft.utils.R;
|
||||
import com.szxgl.nft.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -39,12 +41,12 @@ public class UserController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public R login(String openid,String seed,String code, HttpServletRequest request,Integer flag){
|
||||
// String openid = CookieUtil.getCookie(request.getCookies());
|
||||
// if(StringUtils.isBlank(openid)){
|
||||
// log.error("openid为空:"+openid);
|
||||
// throw new ParameterException("openid为空");
|
||||
// }
|
||||
public R login(String seed,String code, HttpServletRequest request,Integer flag){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
if(StringUtils.isBlank(code)){
|
||||
log.error("验证码不能为空!");
|
||||
return R.error("验证码不能为空!");
|
||||
@ -74,24 +76,23 @@ public class UserController {
|
||||
* @return 有值表示已绑定手机号 walletAddr如果有值表示
|
||||
*/
|
||||
@PostMapping("/getPhone")
|
||||
public R getPhone(String openid,HttpServletRequest request){
|
||||
// String openid = CookieUtil.getCookie(request.getCookies());
|
||||
// if(StringUtils.isBlank(openid)){
|
||||
// log.error("openid为空:"+openid);
|
||||
// throw new ParameterException("openid为空");
|
||||
// }
|
||||
UserDO userDO = userService.getPhone(openid);
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
if(userDO != null){
|
||||
public R getPhone(HttpServletRequest request){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
Map<String, Object> map = nftPhotoService.getNftPhotoUrl(openid);
|
||||
if(map != null ){
|
||||
//手机号已绑定
|
||||
map.put("walletAddr",userDO.getWalletAddr());
|
||||
map.remove("name");
|
||||
map.put("flag",true);
|
||||
return R.ok(map);
|
||||
}else {
|
||||
//手机号未绑定
|
||||
map.put("walletAddr","");
|
||||
map.put("flag",false);
|
||||
return R.ok(map);
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put("flag",false);
|
||||
return R.ok(map2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.szxgl.nft.controller;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.szxgl.nft.entity.RedisKeyName;
|
||||
import com.szxgl.nft.utils.AliyunSmsUtils;
|
||||
import com.szxgl.nft.utils.CookieUtil;
|
||||
import com.szxgl.nft.utils.R;
|
||||
import com.szxgl.nft.utils.RedisUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -30,12 +31,12 @@ public class VerificationCodeController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/getCode")
|
||||
public R getCode(String openid, String seed, HttpServletRequest request){
|
||||
// String openid = CookieUtil.getCookie(request.getCookies());
|
||||
// if(StringUtils.isBlank(openid)){
|
||||
// log.error("openid为空:"+openid);
|
||||
// throw new ParameterException("openid为空");
|
||||
// }
|
||||
public R getCode(String seed, HttpServletRequest request){
|
||||
String openid = CookieUtil.getCookie(request.getCookies());
|
||||
if(StringUtils.isBlank(openid)){
|
||||
log.error("openid为空:"+openid);
|
||||
return R.error("openid为空");
|
||||
}
|
||||
//判断手机号是否为空
|
||||
if(StringUtils.isBlank(seed)){
|
||||
log.error("手机号为空:"+seed);
|
||||
|
||||
@ -31,20 +31,15 @@ import java.util.Date;
|
||||
@Slf4j
|
||||
public class WebAuthFilter implements Filter {
|
||||
|
||||
//@Value("${wx.appid}")
|
||||
private String default_appid = "wx35766a64d73d08a9";
|
||||
private static final String default_appid = "wx35766a64d73d08a9";
|
||||
|
||||
//@Value("${wx.auth-code}")
|
||||
private String key = "fbc35e02df8a4fae9f9f827156acd91e";
|
||||
private static final String key = "fbc35e02df8a4fae9f9f827156acd91e";
|
||||
|
||||
//@Value("${wx.project-id}")
|
||||
private String projectId = "20210001000100011";
|
||||
private static final String projectId = "20210001000100011";
|
||||
|
||||
//@Value("${wx.auth-scope}")
|
||||
private String default_scope = "snsapi_base";
|
||||
private static final String default_scope = "snsapi_base";
|
||||
|
||||
//@Value("${wx.api-domain}")
|
||||
private String api_domain = "https://wx.xfhd.net/thirdparty";
|
||||
private static final String api_domain = "https://wx.xfhd.net/thirdparty";
|
||||
|
||||
// private static String default_appid = "wx35766a64d73d08a9";
|
||||
// private static String key = "adsagdagefghfhgffsghdfsgd";
|
||||
@ -69,11 +64,11 @@ public class WebAuthFilter implements Filter {
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("default_appid:"+default_appid);
|
||||
log.info("key:"+key);
|
||||
log.info("projectId:"+projectId);
|
||||
log.info("default_scope:"+default_scope);
|
||||
log.info("api_domain:"+api_domain);
|
||||
// log.info("default_appid:"+default_appid);
|
||||
// log.info("key:"+key);
|
||||
// log.info("projectId:"+projectId);
|
||||
// log.info("default_scope:"+default_scope);
|
||||
// log.info("api_domain:"+api_domain);
|
||||
|
||||
// Mozilla/5.0 (Linux; Android 4.4.4; iToolsVM Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/33.0.0.0 Mobile Safari/537.36 MicroMessenger/6.3.31.940 NetType/WIFI Language/zh_CN
|
||||
// 每次授权成功后发现会有重复的请求进来,IP为微信上海服务器的IP,useragent包含iToolsVM,暂不明原因,所以直接过滤掉
|
||||
|
||||
@ -15,4 +15,6 @@ public interface NftPhotoMapper extends BaseMapper<NftPhotoDO> {
|
||||
void addNftPhoto(@Param("id") Long id,@Param("seed") String seed);
|
||||
|
||||
Map<String,Object> getNftPhotoUrl(String openid);
|
||||
|
||||
Map<String, Object> getPhoneAndHash(String openid);
|
||||
}
|
||||
|
||||
@ -8,7 +8,9 @@ public interface NftPhotoService {
|
||||
|
||||
UserNftPhoto getNftPhoto(String phone);
|
||||
|
||||
void addPhonePaintingHash(String seed,String openid,Integer flag);
|
||||
void addPhonePaintingHash(String openid,String seed,Integer flag);
|
||||
|
||||
Map<String,Object> getNftPhotoUrl(String seed);
|
||||
|
||||
Map<String, Object> getPhoneAndHash(String openid);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package com.szxgl.nft.service;
|
||||
|
||||
import com.szxgl.nft.entity.UserDO;
|
||||
import com.szxgl.nft.utils.R;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
@ -8,7 +9,9 @@ public interface UserService {
|
||||
|
||||
void addUser(UserDO userDO);
|
||||
|
||||
void addPhone(String seed, String openid);
|
||||
R addPhone(String seed, String openid);
|
||||
|
||||
UserDO getPhone(String openid);
|
||||
UserDO getPhone(String seed);
|
||||
|
||||
void addUserNftPhoto(String openid, String nickname,String walletAddr);
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ public class NftPhotoServiceImpl implements NftPhotoService {
|
||||
|
||||
@Override
|
||||
@Transient
|
||||
public void addPhonePaintingHash(String seed,String openid,Integer flag) {
|
||||
public void addPhonePaintingHash(String openid,String seed,Integer flag) {
|
||||
UserNftPhoto userNftPhoto = getNftPhoto(seed);
|
||||
//非定向人群
|
||||
if(userNftPhoto == null ){
|
||||
@ -48,4 +48,9 @@ public class NftPhotoServiceImpl implements NftPhotoService {
|
||||
return nftPhotoMapper.getNftPhotoUrl(openid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getPhoneAndHash(String openid) {
|
||||
return nftPhotoMapper.getPhoneAndHash(openid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.szxgl.nft.entity.UserDO;
|
||||
import com.szxgl.nft.mapper.UserMapper;
|
||||
import com.szxgl.nft.service.UserService;
|
||||
import com.szxgl.nft.utils.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -24,22 +25,38 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
@Override
|
||||
public void addUser(UserDO userDO) {
|
||||
|
||||
userMapper.insert(userDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPhone(String seed, String openid) {
|
||||
public R addPhone(String seed, String openid) {
|
||||
//手机号是否已被用户绑定
|
||||
UserDO user = getPhone(seed);
|
||||
if(user != null ){
|
||||
return R.error("手机号已被用户绑定!");
|
||||
}
|
||||
UserDO userDo = getUserDo(openid);
|
||||
UpdateWrapper<UserDO> wrapper = new UpdateWrapper<>();
|
||||
wrapper.set("phone",seed);
|
||||
wrapper.eq("openid",openid);
|
||||
userMapper.update(userDo,wrapper);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserDO getPhone(String openid) {
|
||||
public UserDO getPhone(String seed) {
|
||||
QueryWrapper<UserDO> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("openid",openid);
|
||||
wrapper.eq("phone",seed);
|
||||
return userMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserNftPhoto(String openid, String nickname,String walletAddr) {
|
||||
UserDO userDo = getUserDo(openid);
|
||||
UpdateWrapper<UserDO> wrapper = new UpdateWrapper<>();
|
||||
wrapper.set("nickname",nickname);
|
||||
wrapper.set("wallet_addr",walletAddr);
|
||||
wrapper.eq("openid",openid);
|
||||
userMapper.update(userDo,wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,234 +0,0 @@
|
||||
package com.szxgl.nft.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpHeaders;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.config.CookieSpecs;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* HttpClients 请求工具类
|
||||
*
|
||||
* @author Leon
|
||||
* @datetime 2018年8月13日 下午4:42:17
|
||||
*/
|
||||
public class HttpClientUtil {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);
|
||||
|
||||
private static final CloseableHttpClient httpClient;
|
||||
|
||||
static {
|
||||
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).setConnectTimeout(5000).setSocketTimeout(5000).build();
|
||||
httpClient = HttpClientBuilder.create().setDefaultRequestConfig(globalConfig).build();
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject doPost(String url, JSONObject json) {
|
||||
// CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(globalConfig).build();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
JSONObject response = null;
|
||||
CloseableHttpResponse res = null;
|
||||
try {
|
||||
// 设置请求的header
|
||||
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
|
||||
httpPost.setHeader("Accept", "application/json;charset=utf-8");
|
||||
//--------------------设置不使用长连接-----------------------------
|
||||
httpPost.setHeader(HttpHeaders.CONNECTION, "close");
|
||||
StringEntity s = new StringEntity(formatPostData(json), "UTF-8");
|
||||
//s.setContentEncoding("UTF-8");
|
||||
// s.setContentType("x-www-form-urlencoded");//发送json数据需要设置contentType
|
||||
httpPost.setEntity(s);
|
||||
|
||||
res = httpClient.execute(httpPost);
|
||||
int statusCode = res.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
logger.info("请求接口返回状态吗, getStatusCode=" + statusCode + ", getReasonPhrase=" + res.getStatusLine().getReasonPhrase());
|
||||
httpPost.abort();
|
||||
throw new Exception("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
|
||||
HttpEntity entity = res.getEntity();
|
||||
if (entity != null) {
|
||||
String result = EntityUtils.toString(entity, "UTF-8");
|
||||
response = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("HTTP-POST请求出错, URL=" + url + "请求数据:" + json, e);
|
||||
} finally {
|
||||
httpPost.releaseConnection();
|
||||
if (res != null) {
|
||||
try {
|
||||
EntityUtils.consume(res.getEntity());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
try {
|
||||
res.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
//----------------------关闭-----------------------------
|
||||
if (httpPost != null) {
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public static String doPost(String url, Map<String, String> params, String charset) {
|
||||
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtils.isBlank(charset)) {
|
||||
charset = "utf-8";
|
||||
}
|
||||
HttpPost httpPost = null;
|
||||
try {
|
||||
List<NameValuePair> pairs = null;
|
||||
if (params != null && !params.isEmpty()) {
|
||||
pairs = new ArrayList<NameValuePair>(params.size());
|
||||
for (Entry<String, String> entry : params.entrySet()) {
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
pairs.add(new BasicNameValuePair(entry.getKey(), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
httpPost = new HttpPost(url);
|
||||
if (pairs != null && pairs.size() > 0) {
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(pairs, charset));
|
||||
}
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if (statusCode != 200) {
|
||||
httpPost.abort();
|
||||
throw new RuntimeException("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
HttpEntity entity = response.getEntity();
|
||||
String result = null;
|
||||
if (entity != null) {
|
||||
result = EntityUtils.toString(entity, charset);
|
||||
}
|
||||
EntityUtils.consume(entity);
|
||||
response.close();
|
||||
// System.out.println("------------"+result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
if (httpPost != null) {
|
||||
httpPost.abort();
|
||||
|
||||
}
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* GET请求
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject doGet(String url) {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
CloseableHttpResponse res = null;
|
||||
JSONObject response = null;
|
||||
try {
|
||||
// 设置请求的header
|
||||
httpGet.setHeader("Content-Type", "application/json;charset=utf-8");
|
||||
httpGet.setHeader("Accept", "application/json;charset=utf-8");
|
||||
|
||||
res = httpClient.execute(httpGet);
|
||||
int statusCode = res.getStatusLine().getStatusCode();
|
||||
if (statusCode != HttpStatus.SC_OK) {
|
||||
logger.info("请求接口返回状态码, getStatusCode=" + statusCode + ", getReasonPhrase=" + res.getStatusLine().getReasonPhrase());
|
||||
httpGet.abort();
|
||||
throw new Exception("HttpClient,error status code :" + statusCode);
|
||||
}
|
||||
|
||||
HttpEntity entity = res.getEntity();
|
||||
if (entity != null) {
|
||||
String result = EntityUtils.toString(entity, "UTF-8");
|
||||
response = JSONObject.parseObject(result);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("HTTP-GET请求出错, URL=" + url, e);
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
if (res != null) {
|
||||
try {
|
||||
EntityUtils.consume(res.getEntity());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
try {
|
||||
res.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
protected static String formatPostData(JSONObject json) {
|
||||
String result = null;
|
||||
try {
|
||||
JSONObject jsonObject = json;
|
||||
if (jsonObject != null) {
|
||||
result = "?";
|
||||
for (Entry<String, Object> entry : jsonObject.entrySet()) {
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
result = entry.getKey() + "=" + entry.getValue();
|
||||
} else {
|
||||
result += "&" + entry.getKey() + "=" + entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static String formatPostData(String strdata) {
|
||||
String result = strdata;
|
||||
try {
|
||||
JSONObject jsonObject = JSONObject.parseObject(strdata);
|
||||
if (jsonObject != null) {
|
||||
result = "";
|
||||
for (Entry<String, Object> entry : jsonObject.entrySet()) {
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
result = entry.getKey() + "=" + entry.getValue();
|
||||
} else {
|
||||
result += "&" + entry.getKey() + "=" + entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
181
src/main/java/com/szxgl/nft/utils/HttpClientUtils.java
Normal file
181
src/main/java/com/szxgl/nft/utils/HttpClientUtils.java
Normal file
@ -0,0 +1,181 @@
|
||||
package com.szxgl.nft.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* HttpClient4.3工具类*/
|
||||
public class HttpClientUtils
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(HttpClientUtils.class); // 日志记录
|
||||
|
||||
private static RequestConfig requestConfig = null;
|
||||
|
||||
static
|
||||
{
|
||||
// 设置请求和传输超时时间
|
||||
requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输json参数
|
||||
* @param url url地址
|
||||
* @param jsonParam 参数
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject httpPost(String url, JSONObject jsonParam)
|
||||
{
|
||||
// post请求返回结果
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
JSONObject jsonResult = null;
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
// 设置请求和传输超时时间
|
||||
httpPost.setConfig(requestConfig);
|
||||
try
|
||||
{
|
||||
if (null != jsonParam)
|
||||
{
|
||||
// 解决中文乱码问题
|
||||
StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
CloseableHttpResponse result = httpClient.execute(httpPost);
|
||||
// 请求发送成功,并得到响应
|
||||
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
|
||||
{
|
||||
String str = "";
|
||||
try
|
||||
{
|
||||
// 读取服务器返回过来的json字符串数据
|
||||
str = EntityUtils.toString(result.getEntity(), "utf-8");
|
||||
// 把json字符串转换成json对象
|
||||
jsonResult = JSONObject.parseObject(str);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("post请求提交失败:" + url, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("post请求提交失败:" + url, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* post请求传输String参数 例如:name=Jack&sex=1&type=2
|
||||
* Content-type:application/x-www-form-urlencoded
|
||||
* @param url url地址
|
||||
* @param strParam 参数
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject httpPost(String url, String strParam)
|
||||
{
|
||||
// post请求返回结果
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
JSONObject jsonResult = null;
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
httpPost.setConfig(requestConfig);
|
||||
try
|
||||
{
|
||||
if (null != strParam)
|
||||
{
|
||||
// 解决中文乱码问题
|
||||
StringEntity entity = new StringEntity(strParam, "utf-8");
|
||||
entity.setContentEncoding("UTF-8");
|
||||
entity.setContentType("application/x-www-form-urlencoded");
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
CloseableHttpResponse result = httpClient.execute(httpPost);
|
||||
// 请求发送成功,并得到响应
|
||||
if (result.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
|
||||
{
|
||||
String str = "";
|
||||
try
|
||||
{
|
||||
// 读取服务器返回过来的json字符串数据
|
||||
str = EntityUtils.toString(result.getEntity(), "utf-8");
|
||||
// 把json字符串转换成json对象
|
||||
jsonResult = JSONObject.parseObject(str);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("post请求提交失败:" + url, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("post请求提交失败:" + url, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
httpPost.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送get请求
|
||||
* @param url 路径
|
||||
* @return
|
||||
*/
|
||||
public static JSONObject httpGet(String url)
|
||||
{
|
||||
// get请求返回结果
|
||||
JSONObject jsonResult = null;
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
// 发送get请求
|
||||
HttpGet request = new HttpGet(url);
|
||||
request.setConfig(requestConfig);
|
||||
try
|
||||
{
|
||||
CloseableHttpResponse response = client.execute(request);
|
||||
|
||||
// 请求发送成功,并得到响应
|
||||
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
|
||||
{
|
||||
// 读取服务器返回过来的json字符串数据
|
||||
HttpEntity entity = response.getEntity();
|
||||
String strResult = EntityUtils.toString(entity, "utf-8");
|
||||
// 把json字符串转换成json对象
|
||||
jsonResult = JSONObject.parseObject(strResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.error("get请求提交失败:" + url);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
logger.error("get请求提交失败:" + url, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
request.releaseConnection();
|
||||
}
|
||||
return jsonResult;
|
||||
}
|
||||
|
||||
}
|
||||
@ -56,4 +56,22 @@ public class R extends HashMap<String, Object> {
|
||||
super.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// String phone = encrypt("15023451234");
|
||||
// System.out.println(phone);
|
||||
System.out.println(AliyunSmsUtils.getNewcode());
|
||||
}
|
||||
|
||||
//字符串加密
|
||||
public static String encrypt(String seed){
|
||||
String phone = "";
|
||||
try {
|
||||
EncryptUtil encryptUtil = new EncryptUtil();
|
||||
phone = encryptUtil.encrypt(seed);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return phone;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.szxgl.nft.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.codec.digest.UnixCrypt;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
@ -1441,6 +1442,7 @@ public class Utility implements Serializable {
|
||||
public static void main(String[] args) {
|
||||
String url = httpTohttps("http://wx.qlogo.cn/mmopen/tolX9TNpO");
|
||||
System.out.println("url = "+url);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,10 +50,3 @@ spring:
|
||||
min-idle: 5 # 连接池中的最小空闲连接
|
||||
|
||||
|
||||
|
||||
wx:
|
||||
appid: wx35766a64d73d08a9
|
||||
project-id: 20202000200020002
|
||||
api-domain: https://wx.xfhd.net/thirdparty
|
||||
auth-code: 1a9caed163104e2e9056c58b989347b9
|
||||
auth-scope: snsapi_userinfo
|
||||
|
||||
49
src/main/resources/application-prod.yml
Normal file
49
src/main/resources/application-prod.yml
Normal file
@ -0,0 +1,49 @@
|
||||
spring:
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
druid:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://rm-wz9vza84pe0hb338kbo.mysql.rds.aliyuncs.com:3306/2022_pars_nft?autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=GMT%2B8&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
|
||||
username: root
|
||||
password: 'lyg8266@Qiween#com'
|
||||
initial-size: 5
|
||||
max-active: 500
|
||||
min-idle: 10
|
||||
max-wait: 60000
|
||||
pool-prepared-statements: true
|
||||
max-pool-prepared-statement-per-connection-size: 20
|
||||
time-between-eviction-runs-millis: 60000
|
||||
min-evictable-idle-time-millis: 300000
|
||||
validation-query: 'SELECT 1'
|
||||
test-while-idle: true
|
||||
test-on-borrow: false
|
||||
test-on-return: false
|
||||
stat-view-servlet:
|
||||
enabled: true
|
||||
url-pattern: /druid/*
|
||||
#login-username: admin
|
||||
#login-password: admin
|
||||
filter:
|
||||
stat:
|
||||
log-slow-sql: true
|
||||
slow-sql-millis: 1000
|
||||
merge-sql: false
|
||||
wall:
|
||||
config:
|
||||
multi-statement-allow: true
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 500MB
|
||||
max-request-size: 500MB
|
||||
redis:
|
||||
database: 0
|
||||
host: r-wz97jov3cc4roi3b1ppd.redis.rds.aliyuncs.com
|
||||
port: 19088
|
||||
password: 'Xfhd@2020' # 密码
|
||||
timeout: 6000ms # 连接超时时长(毫秒)
|
||||
jedis:
|
||||
pool:
|
||||
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
|
||||
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||
max-idle: 10 # 连接池中的最大空闲连接
|
||||
min-idle: 5 # 连接池中的最小空闲连接
|
||||
@ -7,7 +7,7 @@ spring:
|
||||
# mvc:
|
||||
# dispatch-options-request: true
|
||||
jmx:
|
||||
default-domain: nft
|
||||
default-domain: pars-nft
|
||||
profiles:
|
||||
active: dev
|
||||
# mvc:
|
||||
|
||||
10
src/main/resources/index.html
Normal file
10
src/main/resources/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -44,7 +44,18 @@
|
||||
nft_photo np
|
||||
INNER JOIN user_nft_photo up ON np.id = up.nft_photo_id
|
||||
INNER JOIN `user` u ON up.phone = u.phone
|
||||
where u.openid = '1234'
|
||||
where u.openid = #{openid}
|
||||
</select>
|
||||
|
||||
<select id="getPhoneAndHash" resultType="java.util.Map">
|
||||
SELECT
|
||||
u.phone,
|
||||
np.painting_hash
|
||||
FROM
|
||||
nft_photo np
|
||||
INNER JOIN user_nft_photo unp ON np.id = unp.nft_photo_id
|
||||
INNER JOIN USER u ON u.phone = unp.phone
|
||||
where u.openid = #{openid}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user