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.
227 lines
7.3 KiB
227 lines
7.3 KiB
package com.example.demo.Util;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.net.URLEncoder;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
/**
|
|
* @开发目的: 测试使用
|
|
* @开发人员: 弘历研发部 刘志红
|
|
* @开发时间: 2024-1-26下午1:42:18
|
|
* @软件版本: V1.0
|
|
*/
|
|
public class GoldTistV2 {
|
|
|
|
|
|
|
|
|
|
private static String url = "http://hcm.rzfwq.com/hwhcnewA/";
|
|
|
|
|
|
/**
|
|
* <pre>
|
|
* 发送不带参数的GET的HTTP请求
|
|
* </pre>
|
|
*
|
|
* @param reqUrl HTTP请求URL
|
|
* @return HTTP响应的字符串
|
|
*/
|
|
public static String doGet(String reqUrl) {
|
|
HttpURLConnection url_con = null;
|
|
String responseContent = null;
|
|
try {
|
|
StringBuffer params = new StringBuffer();
|
|
String queryUrl = reqUrl;
|
|
int paramIndex = reqUrl.indexOf("?");
|
|
|
|
if (paramIndex > 0) {
|
|
queryUrl = reqUrl.substring(0, paramIndex);
|
|
String parameters = reqUrl.substring(paramIndex + 1, reqUrl.length());
|
|
String[] paramArray = parameters.split("&");
|
|
for (int i = 0; i < paramArray.length; i++) {
|
|
String string = paramArray[i];
|
|
int index = string.indexOf("=");
|
|
if (index > 0) {
|
|
String parameter = string.substring(0, index);
|
|
String value = string.substring(index + 1, string.length());
|
|
params.append(parameter);
|
|
params.append("=");
|
|
params.append(URLEncoder.encode(value, "UTF-8"));
|
|
params.append("&");
|
|
}
|
|
}
|
|
|
|
params = params.deleteCharAt(params.length() - 1);
|
|
}
|
|
|
|
URL url = new URL(queryUrl);
|
|
url_con = (HttpURLConnection) url.openConnection();
|
|
url_con.setRequestMethod("GET");
|
|
System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(500000));// (单位:毫秒)jdk1.4换成这个,连接超时
|
|
System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(500000)); // (单位:毫秒)jdk1.4换成这个,读操作超时
|
|
// url_con.setConnectTimeout(5000);//(单位:毫秒)jdk
|
|
// 1.5换成这个,连接超时
|
|
// url_con.setReadTimeout(5000);//(单位:毫秒)jdk 1.5换成这个,读操作超时
|
|
url_con.setDoOutput(true);
|
|
byte[] b = params.toString().getBytes();
|
|
url_con.getOutputStream().write(b, 0, b.length);
|
|
url_con.getOutputStream().flush();
|
|
url_con.getOutputStream().close();
|
|
InputStream in = url_con.getInputStream();
|
|
BufferedReader rd = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
|
String tempLine = rd.readLine();
|
|
StringBuffer temp = new StringBuffer();
|
|
String crlf = System.getProperty("line.separator");
|
|
while (tempLine != null) {
|
|
temp.append(tempLine);
|
|
temp.append(crlf);
|
|
tempLine = rd.readLine();
|
|
}
|
|
responseContent = temp.toString();
|
|
rd.close();
|
|
in.close();
|
|
}
|
|
catch (IOException e) {
|
|
e.printStackTrace();
|
|
}finally {
|
|
if (url_con != null) {
|
|
url_con.disconnect();
|
|
}
|
|
}
|
|
return responseContent;
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
* 生成 MD5 签名
|
|
*
|
|
* @param params 待签名的参数数组
|
|
* @param secretKey 密钥
|
|
* @return 签名的 MD5 哈希值,若出现异常则返回 null
|
|
*/
|
|
public static String generateSignature(String[] params, String secretKey) {
|
|
// 将参数数组转换为列表,以便进行排序
|
|
List<String> paramList = new ArrayList<String>();
|
|
Collections.addAll(paramList, params);
|
|
// 对参数列表进行排序
|
|
Collections.sort(paramList);
|
|
|
|
// 拼接排序后的参数
|
|
StringBuilder paramString = new StringBuilder();
|
|
for (String param : paramList) {
|
|
paramString.append(param);
|
|
}
|
|
|
|
// 拼接密钥
|
|
paramString.append(secretKey);
|
|
|
|
try {
|
|
// 获取 MD5 消息摘要实例
|
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
// 计算摘要,明确指定字符编码为 UTF-8
|
|
byte[] digest = md.digest(paramString.toString().getBytes("UTF-8"));
|
|
// 将字节数组转换为十六进制字符串
|
|
StringBuilder hexString = new StringBuilder();
|
|
for (byte b : digest) {
|
|
String hex = Integer.toHexString(0xFF & b);
|
|
if (hex.length() == 1) {
|
|
hexString.append('0');
|
|
}
|
|
hexString.append(hex);
|
|
}
|
|
return hexString.toString();
|
|
} catch (NoSuchAlgorithmException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
} catch (java.io.UnsupportedEncodingException e) {
|
|
e.printStackTrace();
|
|
return null;
|
|
}
|
|
}
|
|
/**
|
|
* @功能描述: 生成随机数
|
|
* @开发人员: 弘历研发部 刘志红 于 2024-1-25下午5:45:36 创建
|
|
* @参数介绍: @param len
|
|
* @参数介绍: @return
|
|
* @返回数据: String
|
|
* @版本编号: V1.0
|
|
*/
|
|
public static String RandomUid(int len){
|
|
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjklmnpqrstuvwxyz23456789";
|
|
StringBuilder result = new StringBuilder();
|
|
Random rnd = new Random();
|
|
int strlen = characters.length();
|
|
while (result.length() < 8) { // length of the random string.
|
|
int index = (int) (rnd.nextFloat() * strlen);
|
|
result.append(characters.charAt(index));
|
|
}
|
|
return "JB"+result.toString();
|
|
}
|
|
|
|
/**
|
|
* 类型说明:
|
|
*
|
|
55 免费金币 金币系统退商品
|
|
56 永久金币 金币系统退商品
|
|
57 任务金币 金币系统退商品
|
|
58 免费金币 金币系统退金币
|
|
59 任务金币 金币系统退金币
|
|
* @功能描述: 金币平台更新客户金币
|
|
* @开发人员: 弘历研发部 刘志红 于 2025-3-21下午1:58:13 创建
|
|
* @参数介绍: @param jwcode 账号
|
|
* @参数介绍: @param lx 类型
|
|
* @参数介绍: @param jbs 金币数量
|
|
* @参数介绍: @param remark 备注
|
|
* @参数介绍: @param yjjb 永久金币
|
|
* @参数介绍: @param czr 操作人
|
|
* @参数介绍: @param goodsname 商品名称
|
|
* @参数介绍: @return
|
|
* @返回数据: String 返回状态1加成功2减成功其他失败 -5 金币不足 -6 类型错误 -7签名错误
|
|
* @版本编号: V1.0
|
|
*/
|
|
public static String addCoinNew(String jwcode, int lx, double jbs,
|
|
String remark,double yjjb,String czr,String goodsname){
|
|
//查错误使用
|
|
String sjzfc = RandomUid(10);
|
|
String resp = "";
|
|
try {
|
|
DESGB desjbkc = new DESGB("Jbxt.205");
|
|
String sk = "jwcode="+jwcode+"&number="+jbs+"&uid="+sjzfc+"&remark="+
|
|
remark+"&czr="+czr+"&yjjb="+yjjb+"&czpt=4&goodsname="+goodsname+"&type="+lx;
|
|
System.out.println("签名前:"+sk);
|
|
String sign = generateSignature(sk.split("&"),"222251821eba7efab6d48e388b8f6baa");
|
|
sk = desjbkc.encrypt(new String(sk.getBytes(), "UTF-8"));
|
|
System.out.println(url+"goldUpdate_sign.gold?app=4&sk="+sk+"&sign="+sign);
|
|
resp = doGet(url+"goldUpdate_sign.gold?app=4&sk="+sk+"&sign="+sign);
|
|
}catch (Exception e){
|
|
System.out.println("加金币异常"+e.toString());
|
|
}
|
|
System.out.println(resp);
|
|
return resp;
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
//调用demo
|
|
addCoinNew("94226013",65,-2,"测试",-1,"黄其振","文章11");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|