|
@@ -87,7 +87,7 @@ impl Default for PubReqHead {
|
|
|
sign_type: "md5".to_string(),
|
|
|
sign: "".to_string(),
|
|
|
timestamp: now.format(time_format).unwrap(),
|
|
|
- version: "v1.0".to_string(),
|
|
|
+ version: "1.0".to_string(),
|
|
|
request_id: "".to_string(),
|
|
|
biz_content: "".to_string(),
|
|
|
}
|
|
@@ -382,7 +382,7 @@ impl BalanceRespBody {
|
|
|
|
|
|
pub fn success(data: impl Into<Option<String>>) -> Self {
|
|
|
Self {
|
|
|
- result_code: "000".to_string(),
|
|
|
+ result_code: "0000".to_string(),
|
|
|
result_desc: "success".to_string(),
|
|
|
balance: data.into(),
|
|
|
}
|
|
@@ -504,7 +504,14 @@ impl SearchRespBody {
|
|
|
return Self::error("99", "服务没有响应字段: resp".to_string());
|
|
|
}
|
|
|
};
|
|
|
-
|
|
|
+ if resp.rcode != "00" {
|
|
|
+ let rcode = if resp.rcode=="06"{
|
|
|
+ "0011"
|
|
|
+ }else{
|
|
|
+ &resp.rcode
|
|
|
+ };
|
|
|
+ return Self::error(rcode, format!("{:?}", resp.rmsg));
|
|
|
+ };
|
|
|
let content = match body.msgbody.content {
|
|
|
Some(content) => content,
|
|
|
None => {
|
|
@@ -564,7 +571,7 @@ pub struct PubRespBody<T> {
|
|
|
impl<T> PubRespBody<T> {
|
|
|
pub fn success(data: T) -> Self {
|
|
|
Self {
|
|
|
- result_code: "000".to_string(),
|
|
|
+ result_code: "0000".to_string(),
|
|
|
result_desc: "success".to_string(),
|
|
|
data: Some(data),
|
|
|
}
|
|
@@ -657,7 +664,7 @@ impl PubRespHead {
|
|
|
impl Default for PubRespHead {
|
|
|
fn default() -> Self {
|
|
|
Self {
|
|
|
- code: "000".to_string(),
|
|
|
+ code: "0000".to_string(),
|
|
|
msg: "success".to_string(),
|
|
|
data: "".to_string(),
|
|
|
sign: "".to_string(),
|
|
@@ -706,14 +713,70 @@ pub struct CallbackRespBody {
|
|
|
#[cfg(test)]
|
|
|
#[allow(unused)]
|
|
|
mod tests {
|
|
|
- use crate::config::SdConfig;
|
|
|
+ use std::time::Duration;
|
|
|
+
|
|
|
+ use crate::{
|
|
|
+ backend::{Body, CallbackReqContent, Header, PubMsgBody},
|
|
|
+ config::SdConfig,
|
|
|
+ };
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
+ #[tokio::test]
|
|
|
+ async fn test_callback() {
|
|
|
+ let body = Body {
|
|
|
+ header: Header {
|
|
|
+ version: "V1.0".to_string(),
|
|
|
+ timestamp: "20230419151000".to_string(),
|
|
|
+ seqno: "CP1681888200006".to_string(),
|
|
|
+ appid: "jtceshi".to_string(),
|
|
|
+ secertkey: "aebcc37778fd948b0972013e4d9ac4eb".to_string(),
|
|
|
+ },
|
|
|
+ msgbody: PubMsgBody {
|
|
|
+ content: Some(CallbackReqContent {
|
|
|
+ orderid: "1681888064405103338".to_string(),
|
|
|
+ extorder: "CESHIAAEF13447172744".to_string(),
|
|
|
+ status: "失败".to_string(),
|
|
|
+ code: "99".to_string(),
|
|
|
+ price: "1000000".to_string(),
|
|
|
+ checktime: "20230418170659000".to_string(),
|
|
|
+ attr1: None,
|
|
|
+ attr2: None,
|
|
|
+ attr3: None,
|
|
|
+ }),
|
|
|
+ resp: None::<()>,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ let req = reqwest::Client::builder()
|
|
|
+ // .user_agent(APP_USER_AGENT)
|
|
|
+ .deflate(true)
|
|
|
+ .gzip(true)
|
|
|
+ .brotli(true)
|
|
|
+ .timeout(Duration::from_millis(10000))
|
|
|
+ .no_proxy()
|
|
|
+ // .trust_dns(true)
|
|
|
+ .build()
|
|
|
+ .unwrap();
|
|
|
+ let resp: serde_json::Value = req
|
|
|
+ .post("http://192.144.212.211:13657/callback")
|
|
|
+ .json(&body)
|
|
|
+ .send()
|
|
|
+ .await
|
|
|
+ .unwrap()
|
|
|
+ .json()
|
|
|
+ .await
|
|
|
+ .unwrap();
|
|
|
+ println!("resp: {}", resp);
|
|
|
+ }
|
|
|
+
|
|
|
#[test]
|
|
|
fn test_aaaa() {
|
|
|
let s = "04f97e835ec530a95df4c999ab0184996b68464bf308239ebb692174812fb4c54349fc217ac5ab13ea8313e458e2cf37fa35345afc4290f8d25dc7c8bb37da1a0ff87a7752c8d03998067b3bf9fec1d7e397aba05fb016b3b48e269e9c87c22b6eef61508de4572c7dacd980530dac913f507ad9aa2a2a8c62edae35c21bf3aaa446168989a1350914499322ebb5b37038e432ed8f37e25083e35087b4fc1dbff3488c1e7cd7810712725a1fd78365a73892bf6b45352ca775b7b2e66a334ed93986728d2c2c78af2bbfaeb590d55a494163371c0c5df7";
|
|
|
- let head = PubReqHead{biz_content: s.to_string(), ..Default::default()};
|
|
|
+ let head = PubReqHead {
|
|
|
+ biz_content: s.to_string(),
|
|
|
+ ..Default::default()
|
|
|
+ };
|
|
|
let cfg = Config::default();
|
|
|
let r = head.decopy::<serde_json::Value>(&cfg);
|
|
|
println!("{:#?}", r)
|