package postbank import ( "fmt" "testing" ) const ( merchantId = "YANWEI001" // 模块名称 服开门户网站-文档中心-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 = "A56E64D94612E26095091C7321846979B3FA4AF2DCD3B13375FDE3888F2E126E" // 合作方公钥 publicKey = "04A7DA7EA6F2974F3582DC2BB82190BEAD40C78DC54461020938306FD470C5B0D689DDA8B53D47C16593D67BDC3BE1B6594C4ECB6C536F440CCD02A0405B537873" // 服开与合作方配对公钥 服开门户网站-用户中心-公钥配置-平台生产公钥 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" ) func TestMarketSm4Decrypt(t *testing.T) { respJson := "{\"request\":\"DUgb\\/aU\\/0ahjHU3e93s4fGNj\\/b2XrhpCSqMhC\\/Q2aXt6BK8W2fKfOBBHTBCtR+5cMiESM27ogbR+\\r\\nzvPqJnyUnNvlVbvO6pLxo3AtieKSAlQkyGSa\\/26NpopHbPrvWKl1Ta8rfEDHLkYeZzLisS85GOQN\\r\\nTLdqamxjhP1tJwvlvdfkLd1zVJ\\/QlpmYSLkzCsiWcOmnr8YlqYb5PMKuOl5yM5KNHVMeHCbfIulV\\r\\nkjNFDSdlFlG+HhRS2KLD1TIYGafLt0DOB+PCg\\/WNb1+09KgLJ2kSBlim\\/MGjlw1hiJY0nLcp1yOL\\r\\nZYK4DqCY5ZPeE9sbzxfe\\/PvyMT0MYvIVJD1cLKrLKxFGWpq0+69L9s4IW10aY5uD4yc4iSoPEzq7\\r\\nLzfGJEybZErNSaCKaFa4sB6foMPgHwUXppw5745PDHrcBwuK746kBQx3yVTAI4pjDx4YuxhjrPa+\\r\\nb3I4NY2PG9uFYBoAewxC34Z5Y9RxRzON3dFY0HPPgNymH+CHq\\/B6OUl2ag2vg4bQA7bTJQAtVfhx\\r\\n+QWcSB2SofsD7JTQGBwNScgfRWhQ7ptQbC5BZV+boP+z1JRb0h3GpfOfpbRPDx51WfQbMOztOkpM\\r\\njYhc2DJ3VjM=\",\"signature\":\"c5bbcba4c567af196959ad2eefe39e84e6708837fff38b8fddcf5fcbc36192d5#fa805cc6c3f257f5bc584cf1d9bb9159530053e5944bfacdbf361e3f09c799b4\",\"encryptKey\":\"0449D815DE5CCDC30CFBCB590F7EEE7C8FC306565608B939B8CDFDDDD8A11A188EE787F78342A564B8F19C3FD7D3573CD48883BC7C9A0B195BCA75DD3FAE1CE487F3C955E560A4CEC0FFC039AE341214476E357BA5DBE06F994EF59AC29A97CDC878088D7D7ADB0508BD293EE7E9CC882B\",\"accessToken\":null}" // 解析接到的请求 reqMsg, err := Decrypt(m_id, pri, msoapub, respJson, true) fmt.Println(reqMsg, err) } // 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}" // 解析接到的请求 reqMsg, err := Decrypt(merchantId, privateKey, sopPublicKey, respJson, true) fmt.Println(reqMsg, err) } func TestSm4Encrypt(t *testing.T) { input := "12314" res, err := Encrypt(merchantId, privateKey, sopPublicKey, input, "", true) fmt.Println(res, err) } func TestGenerateKey(t *testing.T) { hexPri, publicKeyHex := GenerateKey() fmt.Println(hexPri, publicKeyHex) }