YouChuKoffee/app/utils/postbank/cmd/sm2_test.go

63 lines
4.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package cmd
import (
"fmt"
"qteam/app/utils/postbank"
"testing"
)
const (
merchantId = "lansexiongdi666"
// 模块名称 服开门户网站-文档中心-API文档-接口方法业务前缀
// 此处默认为普通接口取数币服务模块名称 ecny 文件接口这里传ufile
moduleName = "ecny"
// appID 服开门户网站-用户中心-我的应用-APP_ID
appID = "961925472724332544001"
// url 协议 + 定版ip端口号 + 接口方法业务前缀 + 合作方编号 + 接口地址后缀 + 合作方交易流水号(工具类生成)
url = "http://220.248.252.123:8443/sop-h5/biz/${moduleName}/${merchantId}.htm?partnerTxSriNo=${partnerTxSriNo}"
// h5token h5申请token的url 协议 + 定版ip端口号 + 接口地址业务前缀 + 合作方编号 + 合作方交易流水号(工具类生成)
h5token = "http://220.248.252.123:8443/sop-h5/h5/authToken/apply/${merchantId}?partnerTxSriNo=${partnerTxSriNo}"
// 合作方私钥
privateKey = "7FE05FEB81673ABF0AC4F9EEB99FB03BFE7BE432CA474CB9AAD8E302CAF00766"
// 合作方公钥
publicKey = "0432F7E91033AC40472885B11EB673B1DE942FD555E95CD12E799CC50DD9E93B04A6AC254D725C22DCBD65436D97A46727B09FFFA1B1098EEA8D43F79AAB84F5B1"
// 服开与合作方配对公钥 服开门户网站-用户中心-公钥配置-平台生产公钥
sopPublicKey = "041F63D23554FC1F5A36D43ABD0DE368A202849BCC03BEB34E7EF4F8C478E12F5529DB649B7C2C2DB5F55B4DC89A6EC83A8226218B7D931638DBFC4B344C628C33"
// sopPrivateKey 服开与合作方配对私钥 服开门户网站-用户中心-私钥配置-平台生产私钥
sopPrivateKey = "174AB6AB44FF23A6B65934B54E9D94B00A81D0D50D57DB0C38257E2AFB2D6C35"
// 文件上传接口
// fileUrl = http://220.248.252.123:8443/sop-h5/biz/ufile/upload/接口名/接口版本/合作方编号/appID/流水号
fileUrl = "http://220.248.252.123:8443/sop-h5/biz/ufile/upload/${method}/${version}/${merchantId}/${appID}/${partnerTxSriNo}"
// 解码格式 如果文件下载时解析出来的报文乱码,请改变解码格式
charsetName = "gbk"
m_id = "lansexiongdi666"
pri = "7FE05FEB81673ABF0AC4F9EEB99FB03BFE7BE432CA474CB9AAD8E302CAF00766"
msoapub = "04A3C235C15070E127679628FE024E6C77FFCB1840B4EFBE09D19CBE0EE69BEA231912943984D34C03989771E503DFBB4ECB186F4BBC27764109E63C2875005C81"
soapb = "0432F7E91033AC40472885B11EB673B1DE942FD555E95CD12E799CC50DD9E93B04A6AC254D725C22DCBD65436D97A46727B09FFFA1B1098EEA8D43F79AAB84F5B1"
)
// TestSm4Decrypt test sm4 decrypt
func TestSm4Decrypt(t *testing.T) {
//respJson := "{\n\t\"accessToken\": \"C0A3853384EA0443C2942FF1A1B0757D\",\n\t\"encryptKey\": \"04F15C783C14DBD91DE13696BFCDAA4523F2D6CABB610A8BA809D7224234E53422EA4143ED6C3BD92CB9745A0330142E94C7F6EB36B5601A133F9E7E8C42E18C693BC975AD245EF14FDA9734523F407B7561CC390883D8D45C35DD8E3575970BFD75554EB9119F4A18B65EC5F3AB37D866\",\n\t\"request\": \"JBKuG9pmsYwLgFPJL5nFci9jEgX9M60ebFK8lNteJqJZgZZEF7Sg7+qabTq7AOhHN/u9a+O4Zv8e\\r\\nIncXNC9sFPKOrqRJaMmAZTrDCwD3VhDt/maMn9lQbdkXaqMwo4S1iYiqoni5riS/8ivbFqz4sQvv\\r\\nPoiyIaQCMkqAAEkFxL6aSlPGY7f7kdLHK6cpixT3h2H1coMPuCQrG1J7jnbe+IlPJiVOKn5Hchus\\r\\n4TnHAuH/y9/8W9sW2tILApqm0MUpNxkor3qkAEqkbhciuJJDp/lDqebcJeRt2UET6UtTFTECYEWR\\r\\nNPfQCHKQxMWWserd/wCcWMx8ePPK/UKqUW8Rpg6hncKcC8b0U5i0z3MFuKJscz/DAS/X6Vex9kUp\\r\\njvy5c+ahm/rx0y5pTkNKP9KzVTFE6SffyA3E5NR+6fIQ9VvOU1A/YPiBhCvLF/dCodUk\",\n\t\"signature\": \"60bd9f1bb4a234acf4c8789f048151cbd688538b8f02d2cf87cdd74309c346e6#6aaaad738d9c10b3aaf85c86b5134d95b4d815dc017b43bc9e5e012243eb26f6\"\n}" // 解析接到的请求
respJson := EN()
reqMsg, err := postbank.Decrypt(merchantId, privateKey, sopPublicKey, respJson, true)
fmt.Println(reqMsg, err)
}
func TestSm4Encrypt(t *testing.T) {
input := "{\"body\":{\"voucher_id\":\"1708321361154\",\"voucher_code\":\"AAABt6wYMDBjNf25\",\"short_url\":\"http://test.22233.cn/AAABt6wYMDBjNf25\",\"voucher_sdate\":\"20240219\",\"voucher_edate\":\"20240331\",\"code_type\":\"00\"},\"header\":{\"partnerTxSriNo\":\"\",\"method\":\"\",\"version\":\"1\",\"merchantId\":\"YANWEI001\",\"appID\":\"YANWEI00001\",\"respTime\":\"20240301141359\"}}"
res, err := postbank.Encrypt(merchantId, privateKey, sopPublicKey, input, "", true)
fmt.Println(res, err)
}
func EN() string {
input := "{\"head\":\"{\"appID\":\"PSBC\",\"merchantId\":\"lansexiongdi666\",\"method\":\"points.elecCoupRece\",\"partnerTxSriNo\":\"202406131805225935940667\",\"reqTime\":\"20240613180522\",\"version\":\"1\"}\",\"body\":\"{\"acName\":\"2024年二季度新客开卡礼营销活动\",\"orderNo\":\"20240613001534531\",\"merNo\":\"1000000004\",\"acCode\":\"202403HK110052930016\",\"num\":\"1\",\"svcNo\":\"YCTZBZS0004\",\"transSeq\":\"99360000007202406131805227108867\"}\"}"
res, _ := postbank.Encrypt(merchantId, sopPrivateKey, publicKey, input, "", true)
return res
}
func TestGenerateKey(t *testing.T) {
hexPri, publicKeyHex := postbank.GenerateKey()
fmt.Println(hexPri, publicKeyHex)
}