postman 调试 传base64字符串 原来选xml

上个图

工具类

package org.springblade.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.springblade.modules.tc.mas.Submit;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;

/**
 * 云MAS平台  短信工具类
 */
public class MasUtil {

	public static void main(String[] args) throws Exception {
		String urlString = "http:/xxxx/sms/norsubmit";

		try {
			URL url = new URL(urlString);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.setRequestMethod("POST");
			connection.setDoOutput(true);
			connection.setRequestProperty("Content-Type", "application/xml");
			String postData = GetSmsParam();
			OutputStream outputStream = connection.getOutputStream();
			outputStream.write(postData.getBytes("UTF-8"));
			outputStream.flush();
			outputStream.close();

			int responseCode = connection.getResponseCode();
			System.out.println(responseCode);
			if (responseCode == HttpURLConnection.HTTP_OK) {
				InputStream inputStream = connection.getInputStream();
				BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
				String line;
				StringBuffer response = new StringBuffer();
				while ((line = reader.readLine()) != null) {
					response.append(line);
				}
				reader.close();

				System.out.println("Response: " + response.toString());
			} else {
				System.out.println("POST request failed with response code: " + responseCode);
			}

			connection.disconnect();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * base64
	 *
	 * @param input
	 * @return
	 */
	private static String encodeBase64String(String input) {
		// 将字符串转换为字节数组
		byte[] bytes = input.getBytes();
		// 对字节数组进行Base64编码
		String base64Encoded = Base64.getEncoder().encodeToString(bytes);
		// 输出Base64编码后的字符串
		System.out.println("Base64编码后的字符串:" + base64Encoded);
		return base64Encoded;
	}

	/**
	 * MD5加密(32位小写)
	 *
	 * @param input
	 * @return
	 */
	private static String encryptToMD5(String input) {
		try {
			// 创建MessageDigest对象并指定算法为MD5
			MessageDigest md = MessageDigest.getInstance("MD5");
			// 将字符串转换为字节数组并进行加密
			byte[] mdBytes = md.digest(input.getBytes());
			// 将字节数组转换为对应的十六进制字符串
			StringBuilder hexString = new StringBuilder();
			for (byte mdByte : mdBytes) {
				// 通过位运算和与操作将字节转换为十六进制字符串
				String hex = Integer.toHexString(0xff & mdByte);
				if (hex.length() == 1) hexString.append('0');
				hexString.append(hex);
			}
			// 输出加密后的字符串
			System.out.println("加密后的字符串:" + hexString.toString());
			return hexString.toString();
		} catch (NoSuchAlgorithmException e) {
			// 处理算法不存在的异常
			e.printStackTrace();
		}
		return input;
	}


	public static String GetSmsParam() throws Exception {
		Submit submit = new Submit();
		submit.setEcName("接口联调账号");
		submit.setApId("rtzhxx");
		submit.setSecretKey("asasas");
		submit.setMobiles("asas7");
		submit.setContent("移as生活");
		submit.setSign("bM1asa);
		submit.setAddSerial("");

		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(submit.getEcName());
		stringBuffer.append(submit.getApId());
		stringBuffer.append(submit.getSecretKey());
		stringBuffer.append(submit.getMobiles());
		stringBuffer.append(submit.getContent());
		stringBuffer.append(submit.getSign());
		stringBuffer.append(submit.getAddSerial());
		String selfMac = encryptToMD5(stringBuffer.toString());
		System.out.println("selfMac:" + selfMac);
		submit.setMac(selfMac);
		String param = JSONObject.toJSONString(submit);
		System.out.println("param:" + param);
		String encode = encodeBase64String(param);
		return encode;
	}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值