Skip to content

Commit

Permalink
fix: wechat pay
Browse files Browse the repository at this point in the history
  • Loading branch information
zrll12 committed Mar 21, 2024
1 parent d54a594 commit 04897c0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/service/trade/wechat/recall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use base64::Engine;
use sea_orm::{ActiveModelTrait, EntityTrait, IntoActiveModel};
use sea_orm::ActiveValue::Set;
use serde::Serialize;
use tracing::{error, info};
use tracing::{debug, error, info};
use wechat_pay_rust_sdk::model::WechatPayNotify;
use wechat_pay_rust_sdk::pay::PayNotifyTrait;
use wechat_pay_rust_sdk::response::Certificate;
Expand All @@ -24,14 +24,21 @@ pub async fn wechat_pay_recall(header_map: HeaderMap, body: String) -> Json<Wech
let result = WECHAT_PAY_CLIENT.decrypt_paydata(&chiphertext, &nonce, &associated_data).unwrap();
let id = result.out_trade_no.clone();
info!("Wechat pay recall: {result:?}");

let pub_key = get_public_key().await;
let timestamp = header_map.get("Wechatpay-Timestamp").unwrap().to_str().unwrap();
let nonce = header_map.get("Wechatpay-Nonce").unwrap().to_str().unwrap();
let signature = header_map.get("Wechatpay-Signature").unwrap().to_str().unwrap();
let body = body.as_str();
debug!("Wechat pay recall: {pub_key:?} {timestamp:?} {nonce:?} {signature:?} {body:?}");

//verify signature
if WECHAT_PAY_CLIENT.verify_signatrue(
&get_public_key().await,
header_map.get("Wechatpay-Timestamp").unwrap().to_str().unwrap(),
header_map.get("Wechatpay-Nonce").unwrap().to_str().unwrap(),
header_map.get("Wechatpay-Signature").unwrap().to_str().unwrap(),
serde_json::to_string(&body).unwrap().as_str(),
&pub_key,
&timestamp,
&nonce,
&signature,
&body,
).map_err(|e| {error!("{}", e.to_string())}).is_err() {
return Json(WechatNoticeResponse {
code: "FAIL".to_string(),
Expand Down

0 comments on commit 04897c0

Please sign in to comment.