parent
63872bbe20
commit
ee59acc4e8
@ -0,0 +1 @@ |
|||||||
|
package com.bweb.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.config.*;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.model.HighMerchantModel;
import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.model.ResultProfitSharing;
import com.hai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.*;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/test")
@Api(value = "订单接口")
public class HighTestController {
private static Logger log = LoggerFactory.getLogger(HighTestController.class);
@Resource
private HighMerchantService highMerchantService;
@Resource
private HighMerchantStoreService highMerchantStoreService;
@Resource
private HighGasOilPriceService highGasOilPriceService;
@Resource
private HighOrderService highOrderService;
@Resource
private HighProfitSharingRecordService highProfitSharingRecordService;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource
private HuiLianTongConfig huiLianTongConfig;
@Resource
private UnionPayConfig unionPayConfig;
@RequestMapping(value = "/getBackendToken", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取访问令牌backendToken")
public ResponseData getBackendToken() {
try {
return ResponseMsgUtil.success(UnionUserConfig.getBackendToken());
} catch (Exception e) {
log.error("HighOrderController --> getBackendToken() error!", e);
return ResponseMsgUtil.exception(e);
}
}
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,47 @@ |
|||||||
|
package com.hai.config; |
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean; |
||||||
|
import org.springframework.context.annotation.Configuration; |
||||||
|
import springfox.documentation.builders.ApiInfoBuilder; |
||||||
|
import springfox.documentation.builders.RequestHandlerSelectors; |
||||||
|
import springfox.documentation.service.ApiInfo; |
||||||
|
import springfox.documentation.service.Contact; |
||||||
|
import springfox.documentation.spi.DocumentationType; |
||||||
|
import springfox.documentation.spring.web.plugins.Docket; |
||||||
|
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
||||||
|
|
||||||
|
/** |
||||||
|
* SwaggerConfig.java |
||||||
|
* 项目名称: |
||||||
|
* 包: |
||||||
|
* 类名称: SwaggerConfig.java |
||||||
|
* 类描述: 构建restful api接口文档 |
||||||
|
* 创建人: |
||||||
|
* 创建时间: 2017 下午4:23:45 |
||||||
|
*/ |
||||||
|
@Configuration |
||||||
|
@EnableSwagger2 |
||||||
|
public class SwaggerConfig |
||||||
|
{ |
||||||
|
|
||||||
|
/** |
||||||
|
* 描述api的基本信息 |
||||||
|
* 基本信息会展现在文档页面中 |
||||||
|
* @return [api的基本信息] |
||||||
|
*/ |
||||||
|
ApiInfo apiInfo() |
||||||
|
{ |
||||||
|
return new ApiInfoBuilder().title("hgj-CWeb").description("提供给用户端的接口").termsOfServiceUrl("").version("1.0.0") |
||||||
|
.contact(new Contact("", "", "")).build(); |
||||||
|
} |
||||||
|
|
||||||
|
@Bean |
||||||
|
public Docket customImplementation() |
||||||
|
{ |
||||||
|
return new Docket(DocumentationType.SWAGGER_2).select() |
||||||
|
.apis(RequestHandlerSelectors.basePackage("com")) |
||||||
|
.build().directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) |
||||||
|
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class).apiInfo(apiInfo()); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1 @@ |
|||||||
|
package com.hai.schedule;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.common.utils.WxUtils;
import com.hai.config.*;
import com.hai.dao.HighGasOrderPushMapper;
import com.hai.entity.*;
import com.hai.model.HighMerchantModel;
import com.hai.model.HighMerchantStoreModel;
import com.hai.model.ResponseData;
import com.hai.model.ResultProfitSharing;
import com.hai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.math.BigDecimal;
import java.security.KeyStore;
import java.util.*;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:08
*/
@Controller
@RequestMapping(value = "/test")
@Api(value = "订单接口")
public class HighTestController {
private static Logger log = LoggerFactory.getLogger(HighTestController.class);
@Resource
private HighMerchantService highMerchantService;
@Resource
private HighMerchantStoreService highMerchantStoreService;
@Resource
private HighGasOilPriceService highGasOilPriceService;
@Resource
private HighOrderService highOrderService;
@Resource
private HighProfitSharingRecordService highProfitSharingRecordService;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource
private HuiLianTongConfig huiLianTongConfig;
@Resource
private UnionPayConfig unionPayConfig;
@RequestMapping(value = "/getToken", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取贵州中石化token")
public ResponseData getToken() {
try {
return ResponseMsgUtil.success(huiLianTongConfig.getToken());
} catch (Exception e) {
log.error("HighOrderController --> getToken() error!", e);
return ResponseMsgUtil.exception(e);
}
}
} |
@ -0,0 +1,98 @@ |
|||||||
|
package common; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.ScheduleApplication; |
||||||
|
import com.hai.common.utils.HttpsUtils; |
||||||
|
import com.hai.common.utils.RedisUtil; |
||||||
|
import com.hai.config.HuiLianTongConfig; |
||||||
|
import com.hai.service.HighDiscountAgentCodeService; |
||||||
|
import com.hai.service.HighDiscountUserRelService; |
||||||
|
import com.hai.service.HighUserService; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
||||||
|
import org.springframework.test.context.web.WebAppConfiguration; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @ClassName RegionTest |
||||||
|
* @Description: TODO () |
||||||
|
* @Author 胡锐 |
||||||
|
* @Date 2020/12/29 |
||||||
|
**/ |
||||||
|
@RunWith(SpringJUnit4ClassRunner.class) |
||||||
|
@SpringBootTest(classes = ScheduleApplication.class) |
||||||
|
@WebAppConfiguration |
||||||
|
public class test { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighUserService highUserService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighDiscountUserRelService highDiscountUserRelService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighDiscountAgentCodeService highDiscountAgentCodeService; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private RedisUtil redisUtil; |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HuiLianTongConfig huiLianTongConfig; |
||||||
|
|
||||||
|
@Test |
||||||
|
public void test(){ |
||||||
|
try { |
||||||
|
huiLianTongConfig.getToken(); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
|
||||||
|
requestOrder(); |
||||||
|
} |
||||||
|
|
||||||
|
public static void requestOrder(){ |
||||||
|
|
||||||
|
Map<String, Object> heard = new HashMap<>(); |
||||||
|
heard.put("Cookie", "_ida=oArhO6XxKSvjI9wLP3cTK-iSG8yY"); |
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>();; |
||||||
|
map.put("goodsId", "23423529"); |
||||||
|
map.put("goodsType", "1"); |
||||||
|
map.put("saleCount", "1"); |
||||||
|
|
||||||
|
List<Map<String, Object>> orderList = new ArrayList<>(); |
||||||
|
orderList.add(map); |
||||||
|
|
||||||
|
Map<String, Object> param = new HashMap<>(); |
||||||
|
param.put("highChildOrderList", orderList); |
||||||
|
|
||||||
|
int success = 0 ; |
||||||
|
int fail = 0; |
||||||
|
|
||||||
|
JSONObject object = HttpsUtils.doPost("https://hsgcs.dctpay.com/crest/highOrder/addOrder", param, heard); |
||||||
|
if (object.getString("return_code").equals("000000")) { |
||||||
|
success++; |
||||||
|
System.out.println("提交订单成功"); |
||||||
|
} else { |
||||||
|
fail++; |
||||||
|
System.out.println(object.getString("return_msg")); |
||||||
|
} |
||||||
|
|
||||||
|
System.out.println("成功数量" + success); |
||||||
|
System.out.println("失败数量" + fail); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,132 @@ |
|||||||
|
package com.hai.config; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.pay.util.sdk.WXPayConstants; |
||||||
|
import com.hai.common.utils.HttpsUtils; |
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter; |
||||||
|
import java.security.KeyPair; |
||||||
|
import java.security.KeyPairGenerator; |
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.security.interfaces.RSAPrivateKey; |
||||||
|
import java.security.interfaces.RSAPublicKey; |
||||||
|
import java.util.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* 银联用户信息 |
||||||
|
* @author hurui |
||||||
|
*/ |
||||||
|
public class UnionUserConfig { |
||||||
|
|
||||||
|
private static String requestUrl = "https://open.95516.com/open/access/1.0/backendToken"; |
||||||
|
private static String appId = "1900bc84497cab3b"; |
||||||
|
private static String secret = "665193ddd44248acb461594cfe0ded5b"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取应用访问令牌backendToken |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static JSONObject getBackendToken() { |
||||||
|
Map<String,Object> paramMap = new HashMap<>(); |
||||||
|
paramMap.put("appId", appId); |
||||||
|
paramMap.put("nonceStr", createNonceStr()); |
||||||
|
paramMap.put("timestamp", System.currentTimeMillis()); |
||||||
|
paramMap.put("signature", generateSign(paramMap)); |
||||||
|
return HttpsUtils.doPost(requestUrl, JSONObject.toJSONString(paramMap)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 参数排序 |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
private static String paramSort(final Map<String, Object> param) { |
||||||
|
Set<String> keySet = param.keySet(); |
||||||
|
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||||
|
Arrays.sort(keyArray); |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for (String k : keyArray) { |
||||||
|
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||||
|
continue; |
||||||
|
} |
||||||
|
if (StringUtils.isBlank(sb.toString())) { |
||||||
|
sb.append(k).append("=").append(param.get(k)); |
||||||
|
} else { |
||||||
|
sb.append("&").append(k).append("=").append(param.get(k)); |
||||||
|
} |
||||||
|
} |
||||||
|
param.remove("secret"); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成签名 |
||||||
|
* @param data |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
private static String generateSign(Map<String, Object> data){ |
||||||
|
data.put("secret", secret); |
||||||
|
String sign = sha256(paramSort(data).getBytes()); |
||||||
|
return sign; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 生成随机16位随机字符串 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String createNonceStr(){ |
||||||
|
String sl = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
||||||
|
StringBuilder sb = new StringBuilder(); |
||||||
|
for(int i = 0 ; i < 16 ; i ++){ |
||||||
|
sb.append(sl.charAt(new Random().nextInt(sl.length()))); |
||||||
|
} |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public static String sha256(byte[] data) { |
||||||
|
try { |
||||||
|
MessageDigest md = MessageDigest.getInstance("SHA-256"); |
||||||
|
return bytesToHex(md.digest(data)); |
||||||
|
} catch (Exception ex) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public static String bytesToHex(byte[] bytes) { |
||||||
|
String hexArray = "0123456789abcdef"; |
||||||
|
StringBuilder sb = new StringBuilder(bytes.length * 2); |
||||||
|
for (byte b : bytes) { |
||||||
|
int bi = b & 0xff; |
||||||
|
sb.append(hexArray.charAt(bi >> 4)); |
||||||
|
sb.append(hexArray.charAt(bi & 0xf)); |
||||||
|
} |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
public static Map<String, Object> generatorRSA(){ |
||||||
|
KeyPairGenerator keyGen = null; |
||||||
|
try { |
||||||
|
keyGen = KeyPairGenerator.getInstance("RSA"); |
||||||
|
keyGen.initialize(1024); |
||||||
|
KeyPair keyPair = keyGen.generateKeyPair(); |
||||||
|
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); |
||||||
|
RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); |
||||||
|
|
||||||
|
String publicKeyBase64 = DatatypeConverter.printBase64Binary(publicKey.getEncoded()); |
||||||
|
String privateKeyBase64 = DatatypeConverter.printBase64Binary(privateKey.getEncoded()); |
||||||
|
|
||||||
|
Map<String, Object> map = new HashMap<>(); |
||||||
|
map.put("publicKey", publicKeyBase64); |
||||||
|
map.put("privateKey", privateKeyBase64); |
||||||
|
return map; |
||||||
|
} catch (NoSuchAlgorithmException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue