知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運(yùn)營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >
微信小程序 c#后臺支付結(jié)果回調(diào)
發(fā)表時間:2022-9-6
發(fā)布人:葵宇科技
瀏覽次數(shù):94
又為大家?guī)砗唵蔚腸#后臺支付結(jié)果回調(diào)方法,首先還是要去微信官網(wǎng)下載模板(WxPayAPI),將模板(WxPayAPI)添加到服務(wù)器上,然后在打開WxPayAPI項目中的example文件下的
NativeNotifyPage.aspx打開網(wǎng)頁中的代碼頁如圖:
將以下代碼加入進(jìn)去就能完成:
{
public static string wxJsApiParam { get; set; } //前段顯示
public string return_result = "";
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/plain";
Response.Write("Hello World");
LogHelper.WriteLog(typeof(NativeNotifyPage), "可以運(yùn)行1-1");
String xmlData = http://www.wxapp-union.com/getPostStr();//獲取請求數(shù)據(jù)
if (xmlData =="")
{
}
else
{
var dic = new Dictionary<string, string>
{
{"return_code", "SUCCESS"},
{"return_msg","OK"}
};
var sb = new StringBuilder();
sb.Append("<xml>");
foreach (var d in dic)
{
sb.Append("<" + d.Key + ">" + d.Value + "</" + d.Key + ">");
}
sb.Append("</xml>");
//把數(shù)據(jù)重新返回給客戶端
DataSet ds = new DataSet();
StringReader stram = new StringReader(xmlData);
XmlTextReader datareader = new XmlTextReader(stram);
ds.ReadXml(datareader);
if (ds.Tables[0].Rows[0]["return_code"].ToString() == "SUCCESS")
{
LogHelper.WriteLog(typeof(NativeNotifyPage), "數(shù)據(jù)能返回");
string wx_appid = "";//微信開放平臺審核通過的應(yīng)用APPID
string wx_mch_id = "";//微信支付分配的商戶號
string wx_nonce_str = "";// 隨機(jī)字符串,不長于32位
string wx_sign = "";//簽名,詳見簽名算法
string wx_result_code = "";//SUCCESS/FAIL
string wx_return_code = "";
string wx_openid = "";//用戶在商戶appid下的唯一標(biāo)識
string wx_is_subscribe = "";//用戶是否關(guān)注公眾賬號,Y-關(guān)注,N-未關(guān)注,僅在公眾賬號類型支付有效
string wx_trade_type = "";// APP
string wx_bank_type = "";// 銀行類型,采用字符串類型的銀行標(biāo)識,銀行類型見銀行列表
string wx_fee_type = "";// 貨幣類型,符合ISO4217標(biāo)準(zhǔn)的三位字母代碼,默認(rèn)人民幣:CNY,其他值列表詳見貨幣類型
string wx_transaction_id = "";//微信支付訂單號
string wx_out_trade_no = "";//商戶系統(tǒng)的訂單號,與請求一致。
string wx_time_end = "";// 支付完成時間,格式為yyyyMMddHHmmss,如2009年12月25日9點(diǎn)10分10秒表示為20091225091010。其他詳見時間規(guī)則
int wx_total_fee = 1;// 訂單總金額,單位為分
int wx_cash_fee = 1;//現(xiàn)金支付金額訂單現(xiàn)金支付金額,詳見支付金額
#region 數(shù)據(jù)解析
//列 是否存在
string signstr = "";//需要前面的字符串
//wx_appid
if (ds.Tables[0].Columns.Contains("appid"))
{
wx_appid = ds.Tables[0].Rows[0]["appid"].ToString();
if (!string.IsNullOrEmpty(wx_appid))
{
signstr += "appid=" + wx_appid;
}
}
//wx_bank_type
if (ds.Tables[0].Columns.Contains("bank_type"))
{
wx_bank_type = ds.Tables[0].Rows[0]["bank_type"].ToString();
if (!string.IsNullOrEmpty(wx_bank_type))
{
signstr += "&bank_type=" + wx_bank_type;
}
}
//wx_cash_fee
if (ds.Tables[0].Columns.Contains("cash_fee"))
{
wx_cash_fee = Convert.ToInt32(ds.Tables[0].Rows[0]["cash_fee"].ToString());
signstr += "&cash_fee=" + wx_cash_fee;
}
//wx_fee_type
if (ds.Tables[0].Columns.Contains("fee_type"))
{
wx_fee_type = ds.Tables[0].Rows[0]["fee_type"].ToString();
if (!string.IsNullOrEmpty(wx_fee_type))
{
signstr += "&fee_type=" + wx_fee_type;
}
}
//wx_is_subscribe
if (ds.Tables[0].Columns.Contains("is_subscribe"))
{
wx_is_subscribe = ds.Tables[0].Rows[0]["is_subscribe"].ToString();
if (!string.IsNullOrEmpty(wx_is_subscribe))
{
signstr += "&is_subscribe=" + wx_is_subscribe;
}
}
//wx_mch_id
if (ds.Tables[0].Columns.Contains("mch_id"))
{
wx_mch_id = ds.Tables[0].Rows[0]["mch_id"].ToString();
if (!string.IsNullOrEmpty(wx_mch_id))
{
signstr += "&mch_id=" + wx_mch_id;
}
}
//wx_nonce_str
if (ds.Tables[0].Columns.Contains("nonce_str"))
{
wx_nonce_str = ds.Tables[0].Rows[0]["nonce_str"].ToString();
if (!string.IsNullOrEmpty(wx_nonce_str))
{
signstr += "&nonce_str=" + wx_nonce_str;
}
}
//wx_openid
if (ds.Tables[0].Columns.Contains("openid"))
{
wx_openid = ds.Tables[0].Rows[0]["openid"].ToString();
if (!string.IsNullOrEmpty(wx_openid))
{
signstr += "&openid=" + wx_openid;
}
}
//wx_out_trade_no
if (ds.Tables[0].Columns.Contains("out_trade_no"))
{
wx_out_trade_no = ds.Tables[0].Rows[0]["out_trade_no"].ToString();
if (!string.IsNullOrEmpty(wx_out_trade_no))
{
signstr += "&out_trade_no=" + wx_out_trade_no;
}
}
//wx_result_code
if (ds.Tables[0].Columns.Contains("result_code"))
{
wx_result_code = ds.Tables[0].Rows[0]["result_code"].ToString();
if (!string.IsNullOrEmpty(wx_result_code))
{
signstr += "&result_code=" + wx_result_code;
}
}
//wx_result_code
if (ds.Tables[0].Columns.Contains("return_code"))
{
wx_return_code = ds.Tables[0].Rows[0]["return_code"].ToString();
if (!string.IsNullOrEmpty(wx_return_code))
{
signstr += "&return_code=" + wx_return_code;
}
LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_return_code" + wx_return_code);
}
//wx_sign
if (ds.Tables[0].Columns.Contains("sign"))
{
wx_sign = ds.Tables[0].Rows[0]["sign"].ToString();
//if (!string.IsNullOrEmpty(wx_sign))
//{
// signstr += "&sign=" + wx_sign;
//}
}
//wx_time_end
if (ds.Tables[0].Columns.Contains("time_end"))
{
wx_time_end = ds.Tables[0].Rows[0]["time_end"].ToString();
if (!string.IsNullOrEmpty(wx_time_end))
{
signstr += "&time_end=" + wx_time_end;
}
LogHelper.WriteLog(typeof(NativeNotifyPage), "time_end" + wx_time_end);
}
//wx_total_fee
if (ds.Tables[0].Columns.Contains("total_fee"))
{
wx_total_fee = Convert.ToInt32(ds.Tables[0].Rows[0]["total_fee"].ToString());
signstr += "&total_fee=" + wx_total_fee;
LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_total_fee" + wx_total_fee);
}
//wx_trade_type
if (ds.Tables[0].Columns.Contains("trade_type"))
{
wx_trade_type = ds.Tables[0].Rows[0]["trade_type"].ToString();
if (!string.IsNullOrEmpty(wx_trade_type))
{
signstr += "&trade_type=" + wx_trade_type;
}
}
//wx_transaction_id
if (ds.Tables[0].Columns.Contains("transaction_id"))
{
wx_transaction_id = ds.Tables[0].Rows[0]["transaction_id"].ToString();
if (!string.IsNullOrEmpty(wx_transaction_id))
{
signstr += "&transaction_id=" + wx_transaction_id;
}
LogHelper.WriteLog(typeof(NativeNotifyPage), "wx_transaction_id" + wx_transaction_id);
}
#endregion
//追加key 密鑰
signstr += "&key=" + System.Web.Configuration.WebConfigurationManager.AppSettings["key"].ToString();
//簽名正確
string orderStrwhere = "ordernumber='" + wx_out_trade_no + "'";
if (wx_sign == System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(signstr, "MD5").ToUpper())
{
//簽名正確 處理訂單操作邏輯
}
else
{
//追加備注信息
}
}
else
{
// 返回信息,如非空,為錯誤原因 簽名失敗 參數(shù)格式校驗錯誤
string return_msg = ds.Tables[0].Rows[0]["return_msg"].ToString();
}
return_result = sb.ToString();
}
}
public bool IsReusable
{
get
{
return false;
}
}
//獲得Post過來的數(shù)據(jù)
public string getPostStr()
{
Int32 intLen = Convert.ToInt32(System.Web.HttpContext.Current.Request.InputStream.Length);
byte[] b = new byte[intLen];
System.Web.HttpContext.Current.Request.InputStream.Read(b, 0, intLen);
return System.Text.Encoding.UTF8.GetString(b);
}
}
備注:記得將方法地址加入到統(tǒng)一下單的中去如圖
相關(guān)案例查看更多
相關(guān)閱讀
- 云南建站公司
- 昆明網(wǎng)絡(luò)公司
- 汽車報廢軟件
- 云南網(wǎng)站建設(shè)快速優(yōu)化
- .net網(wǎng)站
- 汽車報廢回收軟件
- 楚雄網(wǎng)站建設(shè)公司
- 海南小程序制作公司
- 百度小程序
- 小程序定制開發(fā)
- 人人商城
- 小程序設(shè)計
- 用戶登錄
- 日歷組件
- 網(wǎng)站建設(shè)優(yōu)化
- typescript
- 網(wǎng)站建設(shè)價格
- 昆明小程序開發(fā)
- 智慧農(nóng)貿(mào)市場
- 網(wǎng)站建設(shè)靠譜公司
- 云南網(wǎng)站建設(shè)方案 doc
- 分銷系統(tǒng)
- 報廢車
- 云南etc小程序
- 搜索引擎排名
- 重慶網(wǎng)站建設(shè)公司
- 網(wǎng)站優(yōu)化公司
- 百度小程序公司
- 怎么做網(wǎng)站
- 文山小程序開發(fā)