.net 站點整合【先鋒支付】線上充值實現簡單整理

龐順龍發表於2019-05-11

.net 站點整合【先鋒支付】線上充值實現簡單整理

其實和其他支付通道一樣,提交充值申請,監測回撥即可

1、提交線上支付


string ucfpayTotalFee = ObjectHandlers.Get("ucfpayTotalFee");

string rechangeType = ObjectHandlers.Get("rechangeType");

string url = ucfpayPostURL + "?";
string merKey = memberKey;
string service = "REQ_GET_TOKEN";
string version = versionID;
string secId = secretId;
string merchantId = memberchantId;
string reqId = DateTime.Now.ToString("yyyyMMddHHmmssffff", DateTimeFormatInfo.InvariantInfo);
merchantNo = reqId;

string[] keykks = Request.Form.AllKeys;

Hashtable paramPar = new Hashtable();
paramPar.Add("service", service);
paramPar.Add("version", version);
paramPar.Add("secId", secId);
paramPar.Add("merchantId", merchantId);
paramPar.Add("reqId", reqId);

string paramString = UcfpayUtils.sortParam(paramPar);
if (paramString.StartsWith("&"))
{
    paramString = paramString.Substring(1);
}
url = url + paramString;
paramString = paramString + merKey;
string sign = UcfpayUtils.md5Sign(paramString.ToString());
url = url + "&sign=" + sign;

//獲取先鋒支付安全token令牌,每次請求唯一token
string token = UcfpayUtils.getToken(url);
singleToken = token;

if (!String.IsNullOrEmpty(token))
{
    //把請求引數打包成陣列,重新生成sign,提交到收銀臺支付請求
    Hashtable paramPar2 = new Hashtable();
    paramPar2.Add("service", "TO_UCF_CASHIER");
    paramPar2.Add("secId", secId);
    paramPar2.Add("version", version);
    paramPar2.Add("token", token);
    paramPar2.Add("merchantId", merchantId);
    paramPar2.Add("merchantNo", merchantNo); //每次訂單號
    paramPar2.Add("source", "1"); //1、pc 2、移動端
    paramPar2.Add("productType", "WE");
    paramPar2.Add("payerId", "");
    paramPar2.Add("amount", (TranDataType.ObjToInt(ucfpayTotalFee) * 100).ToString()); //付款金額 
    paramPar2.Add("transCur", "156");//156人民幣
    paramPar2.Add("accountType", "3"); //1、借記卡 2、信用卡 3、借貸不區分
    paramPar2.Add("productName", "諸葛投資線上支付");
    paramPar2.Add("productInfo", "諸葛投資線上支付");
    paramPar2.Add("returnUrl", ucfpayURL + "/ucfpay/ucfpayReturnUrl");
    paramPar2.Add("noticeUrl", ucfpayURL + "/ucfpay/ucfpayNoticeUrl");
    paramPar2.Add("expireTime", "");
    paramPar2.Add("memo", "");
    string paramString2 = UcfpayUtils.sortParam(paramPar2);
    if (paramString2.StartsWith("&"))
    {
        paramString2 = paramString2.Substring(1);
    }
    string merKey2 = memberKey;
    paramString2 = paramString2 + merKey2;

    //生成本次訂單支付提交sign標識
    string sign2 = UcfpayUtils.md5Sign(paramString2.ToString());
    paramPar2.Add("sign", sign2);

    //組合提交表單資料 
    StringBuilder sbHtml = new StringBuilder();
    sbHtml.Append("<form id='ucfpaysubmit' name='ucfpaysubmit' action='" + ucfpayPostURL + "' method='post'>");

    foreach (DictionaryEntry temp in paramPar2)
    {
        sbHtml.Append("<input type='hidden' name='" + temp.Key + "' value='" + temp.Value + "'/>");
    }

    //submit按鈕控制元件請不要含有name屬性
    sbHtml.Append("<input type='submit' value='確認' style='display:none;'></form>");

    sbHtml.Append("<script>document.forms['ucfpaysubmit'].submit();</script>");

    //新增充值記錄 

    return sbHtml.ToString();

}
2、非同步回撥



string merchantId = String.IsNullOrEmpty(ObjectHandlers.Post("merchantId")) ? "" : ObjectHandlers.Post("merchantId").ToString();
string merchantNo = String.IsNullOrEmpty(ObjectHandlers.Post("merchantNo")) ? "" : ObjectHandlers.Post("merchantNo").ToString();
string amount = String.IsNullOrEmpty(ObjectHandlers.Post("amount")) ? "" : ObjectHandlers.Post("amount").ToString();
string transCur = String.IsNullOrEmpty(ObjectHandlers.Post("transCur")) ? "" : ObjectHandlers.Post("transCur").ToString();
string memo = String.IsNullOrEmpty(ObjectHandlers.Post("memo")) ? "" : ObjectHandlers.Post("memo").ToString();
string tradeNo = String.IsNullOrEmpty(ObjectHandlers.Post("tradeNo")) ? "" : ObjectHandlers.Post("tradeNo").ToString();
string status = String.IsNullOrEmpty(ObjectHandlers.Post("status")) ? "" : ObjectHandlers.Post("status").ToString();
string tradeTime = String.IsNullOrEmpty(ObjectHandlers.Post("tradeTime")) ? "" : ObjectHandlers.Post("tradeTime").ToString();
string sign = String.IsNullOrEmpty(ObjectHandlers.Post("sign")) ? "" : ObjectHandlers.Post("sign").ToString();
Hashtable paramPar = new Hashtable();
paramPar.Add("merchantId", merchantId);
paramPar.Add("merchantNo", merchantNo);
paramPar.Add("amount", amount);
paramPar.Add("transCur", transCur);
paramPar.Add("memo", memo);
paramPar.Add("tradeNo", tradeNo);
paramPar.Add("status", status);
paramPar.Add("tradeTime", tradeTime);
string paramString = UcfpayUtils.sortParam(paramPar);
if (paramString.StartsWith("&"))
{
    paramString = paramString.Substring(1);
}
string merKey = memberKey;
paramString = paramString + merKey;

string mysign = UcfpayUtils.md5Sign(paramString.ToString());

if (mysign.Equals(sign))
{
    #region 業務處理

    if (status.Equals("S"))
    {
 
        return "SUCCESS";
    }
    return "";

    #endregion
}
else
{
    return "SIGN_ERROR";//簽名錯誤
}
3、return 回撥,同2

內容均為作者獨立觀點,不代表八零IT人立場,如涉及侵權,請及時告知。

相關文章