spc-kiosk-pb/Service/BsvPayment/WeChatPay_BaiRong.cs

1809 lines
86 KiB
C#
Raw Permalink Normal View History

2019-06-16 05:12:09 +00:00
//#define PAY_TEST
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.UserFrame;
using Cosmos.ServiceProvider;
using Cosmos.Common;
using Cosmos.CommonManager;
using Cosmos.BaseFrame;
using System.Data;
using System.Collections;
using System.Security.Cryptography;
using System.Net;
using System.Net.Sockets;
using System.Xml;
/*-----------------------------------------------------------------------------------------------*/
// 설 명 : 중국 위챗페이-Bai Rong
// 작 성 자 : 김기락
// 변경 이력 : 2017.09.11 최초 작성
/*-----------------------------------------------------------------------------------------------*/
namespace Cosmos.Service
{
#region Class WeChatXiaoChengxuPay
class WeChatPay_BaiRong : PaymentBase, IPaymentUs
{
protected PosStatus m_cPosStatus = new PosStatus();
private INetworkHttp m_cNetworkHttp = null;
public WeChatPay_BaiRong()
{
m_cPosStatus = (PosStatus)StateObject.POS; // POS 기본정보
m_cNetworkHttp = (INetworkHttp)sManager.InitServiceInstance(ServiceLists.AGENT_NETWORK.DLL, ServiceLists.AGENT_NETWORK.NETWORK_HTTP);
}
#region SearchPayment
/// <summary>
/// 결제 조회
/// </summary>
/// <param name="aParam"></param>
/// <param name="aRet"></param>
/// <returns></returns>
public string SearchPayment(string[] aParam, ref string[] aRet)
{
string sRet = UserCom.RST_ERR;
try
{
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref aParam);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
#endregion
#region GetPayment
/// <summary>
/// 결제 정보 획득
/// </summary>
/// <param name="aParam"></param>
/// <returns></returns>
public object GetPayment(string[] aParam)
{
return m_cPayItem;
}
#endregion
#region SetPayment
/// <summary>
/// 결제 등록
/// </summary>
/// <param name="aParam"></param>
/// <returns></returns>
public string SetPayment(string[] aParam)
{
string sRet = UserCom.RST_ERR;
string sPosMenuKey = "", sInPutType = "", sInPutData = "", sInEncData = "";
string sOutTradeNo = "";
try
{
sPosMenuKey = aParam[0]; // 메뉴키
sInPutType = aParam[1]; // 입력구분 (카드 번호 리딩 타입..)
sInPutData = aParam[2]; // 입력데이터 ( 카드 번호)
sInEncData = aParam[3]; // 카드데이터 ( encrypt 카드 번호, 전달 받을때 암호화되면 연동시에 문제 될 듯 한데, 앞쪽에서 암호화 하지는 않음)
double nPayAmt = CmUtil.DoubleParse(aParam[4]); // 대상금액
sOutTradeNo = aParam[5]; //결제코드 (상가 주문 번호)-yyMMddHHmmssfff9
m_cPayItem = new Column.TR_PAYMENT.DATA(); // 결과 저장 변수 생성
m_cPayItem.PAY_WAY_CD = GetMenuKeyToPayWayCd(sPosMenuKey); // MST_PAY_DC.PAY_DC_GRP_TYPE
m_cPayItem.PAY_DTL_CD_01 = GetMenuKeyToPayDtlCd(sPosMenuKey); // MST_PAY_DC.PAY_DC_CD
//TradeDiv : PosConst.CANCEL_DIV.NORMAL
//TrType : ItemConst.WECHATPAY_BIORONG_TRAN_TYPE.APPROVE
sRet = ExecuteIrt(PosConst.CANCEL_DIV.NORMAL, ItemConst.WECHATPAY_BIORONG_TRAN_TYPE.APPROVE, sInPutType, sInPutData, sInEncData, nPayAmt, "", "", "", "", sOutTradeNo);
if (sRet != UserCom.RST_OK) return sRet;
// 결제 아이템 추가
ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM); // 결제 내역 받아 오기
m_cPayItem.SEQ = alPayItem.Count + 1;
alPayItem.Add(m_cPayItem);
m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
CmUtil.ZeroFillClear(ref aParam);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
#endregion
#region CancelPayment
public string CancelPayment(string[] aParam)
{
//수동 망취소 호출 시에는 ReversePayment() 로 분기 처리 후 바로 리턴, 상태값을 수정하지 않았으므로 Cancel 처럼 상태값 수정 필요는 없음
if(aParam[0].ToString().Equals("REVERSE"))
{
#region
try
{
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[REVERSE]");
return ReversePayment(aParam);
}
catch(Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name
, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
, ex.Message);
return UserCom.RST_ERR;
}
#endregion
}
//직전 결제 취소
string sRet = UserCom.RST_ERR;
string sInPutType = "", sInPutData = "", sInEncData = "";
string sOutTradeNo = "";
try
{
UserLog.WriteLogFile(UserCom.LOG_OP, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[CANCEL]");
#region
int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호
ArrayList aPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
m_cPayItem = (Column.TR_PAYMENT.DATA)aPayItem[nPayRow];
sInPutType = m_cPayItem.OCCUR_ENTRY_05;//입력구분
sInPutData = m_cPayItem.OCCUR_ENTRY_01;//카드번호
sInEncData = m_cPayItem.CanFiller1; // 카드데이터(위쳇 바이롱에서는 없음)
double nPayAmt = m_cPayItem.AMT_ENTRY_01; // 대상금액
string sApprDate = m_cPayItem.OCCUR_ENTRY_03; // 승인일자
string sApprNo = m_cPayItem.OCCUR_ENTRY_02; // 승인번호
string sOrdTransID = sOutTradeNo = m_cPayItem.OCCUR_ENTRY_09; // 원거래번호
string sOrgPayID = m_cPayItem.OCCUR_ENTRY_10; // 원결제구분
sInEncData = "0000" + sApprNo;
sRet = ExecuteIrt(PosConst.CANCEL_DIV.CANCEL, ItemConst.WECHATPAY_BIORONG_TRAN_TYPE.REFUND
, sInPutType, sInPutData, sInEncData, nPayAmt
, sApprDate, sApprNo, sOrdTransID, sOrgPayID, sOutTradeNo);
if (sRet != UserCom.RST_OK) return sRet;
m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;
m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리
//WinManager.ConfirmMessage(sPointType + " " + MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0068));
// 여전법 대응 ///////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
//////////////////////////////////////////////////////////////////////////////////
//LS_ApprDeamon(true);
sRet = UserCom.RST_OK;
#endregion
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
CmUtil.ZeroFillClear(ref aParam);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
#endregion
#region
public string ReversePayment(string[] aParam)
{
string sRet = UserCom.RST_ERR;
//ExecuteIrt(),ExecuteXmlIrt_CanCel() 를 공통 으로 사용하게 되어, 망취소 시에는 사용 되지 않는 변수 많음
//상태값을 수정하지 않았으므로 Cancel 처럼 상태값 수정 필요는 없음
string sInPutType = "", sInPutData = "", sInEncData = "";
string sOutTradeNo = aParam[1];
double nPayAmt = 0;
string sApprDate = "", sApprNo = "", sOrdTransID = sOutTradeNo, sOrgPayID = "";
try
{
//결제시에 fail 이였으므로 결제 승인 정보가 없음.
sRet = ExecuteIrt("REVERSE", ItemConst.WECHATPAY_BIORONG_TRAN_TYPE.REFUND
, sInPutType, sInPutData, sInEncData, nPayAmt
, sApprDate, sApprNo, sOrdTransID, sOrgPayID, sOutTradeNo);// sOrdTransID, sOutTradeNo 만 값 존재...
//LS_ApprDeamon(true);
return sRet;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name
, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()"
, ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
CmUtil.ZeroFillClear(ref aParam);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
#endregion
#region RefundPayment
public string RefundPayment(string[] aParam)
{
string sRet = UserCom.RST_ERR;
string sInPutType = "", sInPutData = "", sInEncData = "";
string sOutTradeNo = "";
try
{
int nPayRow = CmUtil.IntParse(aParam[0]); // 취소할 행번호
// 결제 내역 받아 오기
ArrayList alPayItem = (ArrayList)StateObject.GetItemObject(Column.TR_PAYMENT.ITEM);
m_cPayItem = (Column.TR_PAYMENT.DATA)alPayItem[nPayRow];
sInPutType = m_cPayItem.OCCUR_ENTRY_05;//입력구분
sInPutData = m_cPayItem.OCCUR_ENTRY_01;//카드번호
sInEncData = m_cPayItem.CanFiller1; // 카드데이터(위쳇 바이롱에서는 없음)
double nPayAmt = m_cPayItem.AMT_ENTRY_01; // 대상금액
string sApprDate = m_cPayItem.OCCUR_ENTRY_03; // 승인일자
string sApprNo = m_cPayItem.OCCUR_ENTRY_02; // 승인번호
string sOrdTransID = sOutTradeNo = m_cPayItem.OCCUR_ENTRY_09; // 원거래번호
string sOrgPayID = m_cPayItem.OCCUR_ENTRY_10; // 원결제구분
if (m_cPayItem.OCCUR_ENTRY_08.ToString() != ItemConst.PAY_APP_DIV.NORMAL)
{
//임의 등록 이면 승인 없이 데이터 처리
m_cPayItem.OCCUR_ENTRY_06 = m_cPayItem.OCCUR_ENTRY_02;
m_cPayItem.OCCUR_ENTRY_07 = m_cPayItem.OCCUR_ENTRY_03;
}
else
{
// 취소시 카드번호 대신 '0000' + 승인번호로 대체하여 요청해야 취소 가능
sInEncData = "0000" + sApprNo;
sRet = ExecuteIrt("REFUND", ItemConst.WECHATPAY_BIORONG_TRAN_TYPE.REFUND
, sInPutType, sInPutData, sInEncData, nPayAmt
, sApprDate, sApprNo, sOrdTransID, sOrgPayID, sOutTradeNo);
if (sRet != UserCom.RST_OK) return sRet;
}
//@@ 다른 결제 반품 참고하여 수정 필용
//m_cPayItem.CANCEL_DIV = PosConst.CANCEL_DIV.CANCEL;
//m_cDataService.UpdatePluAmount(); // 상품 합계금액 계산(거래해더)
//m_cDataService.UpdatePayAmount(); // 결제 금액 재 계산 처리
// 여전법 대응 ///////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref m_cPayItem.CanFiller1);
//////////////////////////////////////////////////////////////////////////////////
//LS_ApprDeamon(true);
sRet = UserCom.RST_OK;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
CmUtil.ZeroFillClear(ref aParam);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
#endregion
#region SetMenualPayment
public string SetMenualPayment(string[] aParam)
{
throw new NotImplementedException();
}
#endregion
#region , ,
/// <summary>
///
/// </summary>
/// <param name="sTradeDiv">결제/취소/반품 구분</param>
/// <param name="sTrType">결제/반품 코드 구분</param>
/// <param name="sInPutType">카드번호 입력(리딩) 방식</param>
/// <param name="sInPutData">카드번호</param>
/// <param name="sInEncData">암호화된 카드 번호</param>
/// <param name="nPayAmt">결제할 금액</param>
/// <param name="sApprDate"></param>
/// <param name="sApprNo"></param>
/// <param name="sOrdTransID"></param>
/// <param name="sOrgPayID"></param>
/// <param name="sOutTradeNo">결제 코드</param>
/// <returns></returns>
public string ExecuteIrt(string sTradeDiv, string sTrType
, string sInPutType, string sInPutData, string sInEncData, double nPayAmt
, string sApprDate, string sApprNo, string sOrdTransID, string sOrgPayID, string sOutTradeNo)
{
string sRet = UserCom.RST_ERR;
string sTransID = sOutTradeNo;
try
{
// 승인업체 코드 조회
string sVanCD = PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);//MST_PAY_DC.APPR_VEND_CD
// 연습모드이면 연습 데이터 설정
if( m_cPosStatus.Base.TrainingFlag == "1" || m_cPosStatus.Mst.TestStorYn == "1")
{
return SetTrainingData(sTradeDiv, sTrType, sInPutType, sInPutData, sInEncData, nPayAmt, sApprDate, sApprNo, sTransID, sOrdTransID, sOrgPayID);
}
Hashtable htRecvData = new Hashtable();
if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL) //결제 요청
{
sRet = ExecuteXmlIrt(sTradeDiv, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sVanCD, sTrType
, sInPutType, sInPutData, sInEncData, nPayAmt
, sTransID, sOrdTransID, sApprNo, sOrgPayID, ref htRecvData);
}
else if (sTradeDiv == PosConst.CANCEL_DIV.CANCEL)
{
sRet = ExecuteXmlIrt_CanCel(sTradeDiv, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sVanCD, sTrType
, sInPutData, nPayAmt
, sOrdTransID
, true, ref htRecvData);//, sInPutType, sInEncData, sTransID, sApprNo, sOrgPayID 값은 사용 되지 않음
}
else if (sTradeDiv == "REVERSE")//망취소
{
sRet = ExecuteXmlIrt_CanCel(PosConst.CANCEL_DIV.CANCEL, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sVanCD, sTrType
, sInPutData,nPayAmt
, sOrdTransID
, false, ref htRecvData);//, sInPutType, sInEncData, sTransID, sApprNo, sOrgPayID 값은 사용 되지 않음
}
else if (sTradeDiv == "REFUND")//반품
{
sRet = ExecuteXmlIrt_Refund(PosConst.CANCEL_DIV.CANCEL, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sVanCD, sTrType
, sInPutType, sInPutData, sInEncData, nPayAmt
, sTransID, sOrdTransID, sApprNo, sOrgPayID, ref htRecvData);
}
if (sRet != UserCom.RST_OK) return sRet;
#region
m_cPayItem.PAY_AMT = nPayAmt;
m_cPayItem.PAY_DTL_CD_02 = ""; // 캠페인코드
m_cPayItem.PAY_DTL_CD_03 = "";
m_cPayItem.PAY_DTL_CD_04 = "";
m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY;
m_cPayItem.AMT_ENTRY_01 = nPayAmt; // 사용포인트
m_cPayItem.AMT_ENTRY_02 = 0; // 제휴 할인 금액
m_cPayItem.AMT_ENTRY_03 = 0;
m_cPayItem.AMT_ENTRY_04 = 0;
m_cPayItem.AMT_ENTRY_05 = 0;
m_cPayItem.AMT_ENTRY_06 = 0;
m_cPayItem.AMT_ENTRY_07 = 0;
m_cPayItem.AMT_ENTRY_08 = 0;
m_cPayItem.AMT_ENTRY_09 = 0;
m_cPayItem.AMT_ENTRY_10 = 0;
m_cPayItem.OCCUR_ENTRY_01 = sInPutData; // 카드번호
if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)//승인번호
{
//m_cPayItem.OCCUR_ENTRY_02 = htRecvData.ContainsKey("transaction_id") ? htRecvData["transaction_id"].ToString().Trim() : ""; //결제 번호, htRecvData["out_trade_no"].
//m_cPayItem.OCCUR_ENTRY_02 = htRecvData.ContainsKey("out_trade_no") ? htRecvData["out_trade_no"].ToString().Trim() : ""; //결제 번호
m_cPayItem.OCCUR_ENTRY_02 = sTransID;//위쳇 바이롱에서는 이번호가 상가 주문번호로 승인번호로 사용하여도 됨.
}
else
{
m_cPayItem.OCCUR_ENTRY_02 = sApprNo;
}
m_cPayItem.OCCUR_ENTRY_03 = DateTime.Now.ToString("yyyyMMdd"); // 승인일자
m_cPayItem.OCCUR_ENTRY_04 = DateTime.Now.ToString("HHmmss"); // 승인시간
m_cPayItem.OCCUR_ENTRY_05 = sInPutType; // 입력 구분
m_cPayItem.OCCUR_ENTRY_06 = sApprNo; // 원승인번호
m_cPayItem.OCCUR_ENTRY_07 = sApprDate; // 원승인일자
m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL;
if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
{
m_cPayItem.OCCUR_ENTRY_09 = sTransID; // 전송번호
m_cPayItem.OCCUR_ENTRY_10 = "10005"; // 결제구분 (10001:알리페이, 10004:위챗페이)
}
else
{
m_cPayItem.OCCUR_ENTRY_09 = sOrdTransID; // 원전송번호
m_cPayItem.OCCUR_ENTRY_10 = sOrgPayID; // 원결제구분 (10001:알리페이, 10004:위챗페이)
}
m_cPayItem.OCCUR_ENTRY_11 = "";
m_cPayItem.OCCUR_ENTRY_12 = "";
m_cPayItem.OCCUR_ENTRY_13 = "";
m_cPayItem.OCCUR_ENTRY_16 = sVanCD; // VAN 구분
m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01); // 결제수단명 (바이롱...)
m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL; // (cancel 경우에는 CancelPayment() 에서 재설정함. )
m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo; // 빌분리 번호
#endregion
sRet = UserCom.RST_OK;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
return sRet;
}
#region
/// <summary>
/// 승인실행
/// </summary>
/// <param name="sTradeDiv">결제/직전취소/망취소/반품 구분</param>
/// <param name="sPAY_WAY_CD">결제 수단</param>
/// <param name="sPAY_DTL_CD_01">결제 상세 코드</param>
/// <param name="sVanCD">VAN Code</param>
/// <param name="sTrType">승인구분</param>
/// <param name="sInPutType"></param>
/// <param name="sInPutData">카드번호</param>
/// <param name="sInEncData"></param>
/// <param name="nPayAmt">결제 금액</param>
/// <param name="sTransID">결제코드 (상가 주문 번호)-yyMMddHHmmssfff9</param>
/// <param name="sOrdTransID"></param>
/// <param name="sApprNo"></param>
/// <param name="sOrgPayID"></param>
/// <param name="htRecvData"></param>
/// <returns></returns>
private string ExecuteXmlIrt(string sTradeDiv, string sPAY_WAY_CD, string sPAY_DTL_CD_01, string sVanCD, string sTrType
, string sInPutType, string sInPutData, string sInEncData, double nPayAmt
, string sTransID, string sOrdTransID, string sApprNo, string sOrgPayID, ref Hashtable htRecvData)
{
string sRet = UserCom.RST_ERR;
try
{
Hashtable htRefSendData = new Hashtable();//요청 후 조회에서 사용되는 데이타
// 전문 생성
string stSendData = MakeWeChatBodyData(sVanCD, sInEncData, nPayAmt, sTransID, ref htRefSendData);
string sWriteSendData = CmUtil.MakeLogDataToMask(false, sInEncData, stSendData);//로그로 남기는 데이타에는 카드 번호 마스킹 처리
// 요청 - 승인로그 저장 (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "S", sInPutData, nPayAmt.ToString(), "", "", "", "", "", sWriteSendData });
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[Xiao Wechat pay send data:" + stSendData);
//전문 송.수신
string sRespData = string.Empty;
int iRet = m_cNetworkHttp.HttpPOST_SendReceive(WeXiaoConfig.MICROPAY_URL, "text/xml", stSendData, ref sRespData);
if (iRet != BaseCom.OK)
{
if (m_bErrMsgShow == true) WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0158));//통신 실패
return sRet;
}
//수신 처리
bool isCheckSign = false;
WeXiaoData result = new WeXiaoData();
//SortedDictionary<string, object> dicResult = result.FromResponse(sRespData, ref htRecvData, ref isCheckSign);
result.FromResponse(sRespData, ref htRecvData, ref isCheckSign);
string return_code = string.Empty; string return_msg = string.Empty;
string result_code = string.Empty; string err_code = string.Empty; string err_code_des = string.Empty;
if (result.IsKeyValue("return_code"))
{
#region
return_code = result.GetValue("return_code").ToString();
return_msg = result.IsKeyValue("return_msg") ? result.GetValue("return_msg").ToString() : "";
result_code = result.IsKeyValue("result_code") ? result.GetValue("result_code").ToString() : "";
err_code = result.IsKeyValue("err_code") ? result.GetValue("err_code").ToString() : "";
err_code_des = result.IsKeyValue("err_code_des") ? result.GetValue("err_code_des").ToString() : "";
#endregion
}
//수신 로그 추가
string sWriteRecvData = CmUtil.MakeLogDataToMask(false, sInEncData, sRespData);//수신 데이타 중 카드 번호 일부 마스킹 처리
m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "R", sInPutData, nPayAmt.ToString(), htRefSendData["out_trade_no"].ToString(), DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), return_code + "," + result_code, "return_msg:" + return_msg + ",err_code_des:" + err_code_des, sWriteRecvData });
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[Xiao Wechat pay receive data:" + sRespData);
#region return code check
string sErrorMessage = string.Empty;
if (string.IsNullOrEmpty(return_code))
{
sErrorMessage = "return_code Exception";
sRet = UserCom.RST_ERR;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage + "(" + return_code + ")");
return sRet;
}
if (!return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS))//인터페이스 실패
{
sErrorMessage = return_msg;
sRet = UserCom.RST_ERR;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage + "(" + return_code + ")");
return sRet;
}
//인터페이스 성공, 비지니스 성공
if (return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS) && result_code.ToUpper().Equals(WeXiaoConfig.SUCCESS))
{
sRet = UserCom.RST_OK;
//#if(PAY_TEST)
//err_code = WeXiaoConfig.USERPAYING;
//#else
return sRet;
//#endif
}
#endregion
if (!err_code.ToUpper().Equals(WeXiaoConfig.USERPAYING) && !err_code.ToUpper().Equals(WeXiaoConfig.SYSTEMERROR) && !err_code.ToUpper().Equals(WeXiaoConfig.UNKNOWN))
{
#region ,
if (!err_code_des.Equals("")) sErrorMessage = err_code_des + " (err_code:" + err_code + ")";
else sErrorMessage = return_msg + " (return_code:" + return_code + ")";
sRet = UserCom.RST_ERR;
//isExecWeChatQuery = false;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage);
return sRet;
#endregion
}
if (err_code.ToUpper().Equals(WeXiaoConfig.USERPAYING) || err_code.ToUpper().Equals(WeXiaoConfig.SYSTEMERROR) || err_code.ToUpper().Equals(WeXiaoConfig.UNKNOWN))
{
#region (USERPAYING )
//30초 동안 최대 10회 진행
int retryCount = 0;
int maxRetryCount = 10;
DateTime startTime = DateTime.Now;
TimeSpan durationSec = new TimeSpan(0, 0, 30);//30 초
int queryResultCode = 0;//조회 결과 , queryResultCode = 0 : 명확한 오류 발생으로 재조회 하지 않음 , queryResultCode = 1 : 성공, queryResultCode =2 : 다시 조회
while (startTime.Add(durationSec) > DateTime.Now && retryCount < maxRetryCount)
{
retryCount++;
WeXiaoData resultWeChatQuery = WeCahtQueryResult(htRefSendData, ref queryResultCode);
if (queryResultCode == 1) //success
{
break;
}
else if (queryResultCode == 2) //retry, 다시 조회 시도
{
System.Threading.Thread.Sleep(2500);
continue;
}
else // error , 명확한 오류
{
break;
}
}//while end
if (queryResultCode == 1)
{
sRet = UserCom.RST_OK;
}
else
{
sRet = UserCom.RST_ERR;
//조회 오류 시에 자동으로 망취소, 사용자가 너무 오랫동안 기다릴 가능성도 있어(최대 60 초) UI 에서도 있긴하나 , 제거 여부는 필요에 따라 처리
CancelPayment(new string[] { "REVERSE", htRefSendData["out_trade_no"].ToString() });
}
#endregion
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[wechat query result code, retry count]:" + queryResultCode.ToString() + "," + retryCount.ToString());
}//if else end
}
catch (Exception ex)
{
sRet = UserCom.RST_ERR;
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.ERROR_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.ToString());
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
/// <summary>
/// 위쳇 결제 요청 전문 생성
/// </summary>
/// <param name="sInEncData">QR코드번호</param>
/// <param name="nPayAmt">결제금액</param>
/// <param name="sTransID">결제코드 (상가 주문 번호)-yyMMddHHmmssfff9</param>
/// <param name="htRefSendData">실행 후 참고될 값 </param>
/// <returns></returns>
public string MakeWeChatBodyData(string sVanCD, string sInEncData, double nPayAmt, string sTransID, ref Hashtable htRefSendData)
{
int cost_price = 0;//상품 총 금액
int total_fee = 0; //결제할 금액
string body = string.Empty;
// 결제수단으로 VAN 정보 조회 -- 위쳇에 입점된 점포 코드로 사용
//string sApprID = PosMstManager.GetMstVan(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_VAN.DATA.APPR_ID);//CAT ID(위쳇에서 발행한 점포고유코드)
string sApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.APPR_ID);//CAT ID(위쳇에서 발행한 점포고유코드)
total_fee = (int)CmUtil.DoubleMultiplication(nPayAmt, 100); //(int)nPayAmt * 100
//sApprID = "1485695332";
//string out_trade_no = sTransID;
WeXiaoData data = new WeXiaoData();
data.SetValue("mch_id", sApprID);//위쳇에 입점된 점포 코드
data.SetValue("device_info", m_cPosStatus.Base.StoreNo+"_"+m_cPosStatus.Base.PosNo);
data.SetValue("nonce_str", WeXiaoUtil.MakeNonceString());
data.SetValue("detail", GetGoodsDetail(ref cost_price, ref body));
data.SetValue("body", body);//"파리바게트 구매 대표 상품"
data.SetValue("attach", "");
data.SetValue("out_trade_no", sTransID);
data.SetValue("total_fee", total_fee);
data.SetValue("goods_tag", "");
data.SetValue("limit_pay", "");
data.SetValue("auth_code", sInEncData);//카드번호
data.SetValue("spbill_create_ip", WeXiaoUtil.GetPOS_IP());
data.SetValue("sign", data.MakeSign());//맨 나중에
//data.IsKeyValue(); 필수 key 설정 체크
//조회시에 참조 할 값
htRefSendData.Add("mch_id", sApprID);
htRefSendData.Add("out_trade_no", sTransID);
return data.MakeSendXmlString();
}
/// <summary>
/// 위쳇 결제 요청 시 상품 상세 정보
/// </summary>
/// <param name="total_fee"></param>
/// <param name="body"></param>
/// <returns></returns>
private string GetGoodsDetail(ref int cost_price, ref string body)
{
//frmSaleMain.cs > DisplayItem() 참고
//BsvSale.SalePluItemBase.cs > SetItemCode() 참고
StringBuilder sbDetail = new StringBuilder();
ArrayList aSaleItem = (ArrayList)StateObject.GetItemObject(Column.TR_PLU.ITEM);
int nCostPrice_Fen = 0;//상품 전체 가격 (분)
int nGoodsPrice_Fen = 0; //개당 상품가격 (분)
sbDetail.Append("{");
sbDetail.Append("\"cost_price\":2^31,");//상품 가격(할인된 금액 아님)
sbDetail.Append("\"receipt_id\":\"\",");//영수증 번호
sbDetail.Append("\"goods_detail\":");
sbDetail.Append("[");
if (aSaleItem.Count == 0) sbDetail.Append("{}");//결재창까지 왔다면 이런 경우 없음.
else
{
for (int iRow = 0; iRow < aSaleItem.Count; iRow++)
{
Column.TR_PLU.DATA cSaleItem = (Column.TR_PLU.DATA)aSaleItem[iRow];
if (cSaleItem.CANCEL_DIV == PosConst.CANCEL_DIV.CANCEL || cSaleItem.CANCEL_DIV_MAIN == PosConst.CANCEL_DIV.CANCEL) continue; // 지정취소
nGoodsPrice_Fen = CmUtil.IntParse((cSaleItem.SALE_AMT * 100).ToString());// (int)(Convert.ToDecimal(cSaleItem.BILL_AMT) * 100);
sbDetail.Append("{");
sbDetail.Append("\"goods_id\":\"" + cSaleItem.ITEM_PLU_CD + "\",");
sbDetail.Append("\"goods_name\":\"" + cSaleItem.ITEM_NAME + "\",");
sbDetail.Append("\"quantity\":" + CmUtil.IntParse(cSaleItem.SALE_QTY.ToString()) + ",");
sbDetail.Append("\"price\":" + nGoodsPrice_Fen.ToString() + "");
sbDetail.Append("}");
if (iRow < aSaleItem.Count - 1) sbDetail.Append(",");
nCostPrice_Fen += nGoodsPrice_Fen * CmUtil.IntParse(cSaleItem.SALE_QTY.ToString());
if (iRow == 0) body = cSaleItem.ITEM_NAME;
}
}
sbDetail.Append("]");
sbDetail.Append("}");
cost_price = nCostPrice_Fen;
return sbDetail.ToString().Replace("2^31", nCostPrice_Fen.ToString());
}
#endregion
/// <summary>
/// 연습 데이터 설정
/// </summary>
public string SetTrainingData(string sTradeDiv, string sTrType
, string sInPutType, string sInPutData, string sCardData, double nPayAmt
, string sApprDate, string sApprNo, string sTransID, string sOrdTransID, string sOrgPayID)
{
string sRet = UserCom.RST_ERR;
try
{
// 연습모드이면 연습 데이터 설정
// 승인업체 코드 조회
string sVanCD = PosMstManager.GetMstPayDc(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, PosMst.MST_PAY_DC.DATA.APPR_VEND_CD);//MST_PAY_DC.APPR_VEND_CD
// 결제구분 (1:결제, 2:할인)
DataRow dr = PosMstManager.GetMstPayDc(new string[] { m_cPosStatus.Base.CmpCd, m_cPosStatus.Base.StoreNo, m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01 });
m_cPayItem.PAY_AMT = nPayAmt;
m_cPayItem.PAY_DTL_CD_02 = ""; // 캠페인코드
m_cPayItem.PAY_DTL_CD_03 = "";
m_cPayItem.PAY_DTL_CD_04 = "";
m_cPayItem.PAY_DTL_CD_05 = PosConst.PAY_DC_TYPE.PAY; // 할인결제구분 (1:결제, 2:할인)
m_cPayItem.AMT_ENTRY_01 = nPayAmt; // 사용포인트
m_cPayItem.AMT_ENTRY_02 = 0; // 제휴 할인 금액
m_cPayItem.AMT_ENTRY_03 = 0; // 총포인트
m_cPayItem.AMT_ENTRY_04 = 0; // 가용포인트
m_cPayItem.AMT_ENTRY_05 = 0; // 잔여포인트
m_cPayItem.AMT_ENTRY_08 = 0;
m_cPayItem.OCCUR_ENTRY_01 = sInPutData; // 카드번호
m_cPayItem.OCCUR_ENTRY_02 = "99999999"; // 승인번호
m_cPayItem.OCCUR_ENTRY_03 = DateTime.Now.ToString("yyMMdd"); // 승인일자
m_cPayItem.OCCUR_ENTRY_04 = DateTime.Now.ToString("HHmmss"); // 승인시간
m_cPayItem.OCCUR_ENTRY_05 = sInPutType; // 입력 구분
m_cPayItem.OCCUR_ENTRY_06 = sApprNo; // 원승인번호(최초에는 없음)
m_cPayItem.OCCUR_ENTRY_07 = sApprDate; // 원승인일자(최초에는 없음)
m_cPayItem.OCCUR_ENTRY_08 = ItemConst.PAY_APP_DIV.NORMAL; //승인구분
if (sTradeDiv == PosConst.CANCEL_DIV.NORMAL)
{
m_cPayItem.OCCUR_ENTRY_09 = sTransID; // 전송번호(HHmmssfff)
//if (CmUtil.LeftH(sInPutData, 2) == "13")
// m_cPayItem.OCCUR_ENTRY_10 = "10004"; // 결제구분 (10001:알리페이, 10004:위챗페이)
//else
// m_cPayItem.OCCUR_ENTRY_10 = "10001";
m_cPayItem.OCCUR_ENTRY_10 = "10005"; //결제구분 (10005:위챗페이 - 바이롱)
}
else
{ //(최초에는 없음, 즉 PosConst.CANCEL_DIV.NORMAL 에는 없음.)
m_cPayItem.OCCUR_ENTRY_09 = sOrdTransID; // 원전송번호
m_cPayItem.OCCUR_ENTRY_10 = sOrgPayID; // 원결제구분 (10001:알리페이, 10004:위챗페이)
}
m_cPayItem.OCCUR_ENTRY_11 = "";
m_cPayItem.OCCUR_ENTRY_12 = "";
m_cPayItem.OCCUR_ENTRY_13 = "";
m_cPayItem.OCCUR_ENTRY_16 = sVanCD; // VAN 구분
m_cPayItem.OCCUR_ENTRY_20 = GetPayDtlCdToPayDtlName(m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01); // 결제수단명
//m_cPayItem.CanFiller1 = sCardData;
m_cPayItem.CANCEL_DIV = ItemConst.PAY_CANCEL_DIV.NORMAL;
m_cPayItem.BILLSPR_NO = m_cTrnStatus.Sale.BillSplitNo; // 빌분리 번호
sRet = UserCom.RST_OK;
}
catch (Exception ex)
{
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
return sRet;
}
#endregion
#region
/// <summary>
/// 조회 쿼리 결과
/// </summary>
/// <param name="htRefSendData">결제 요청 시에 사용된 파라메타 중 조회 시에 필요로 하는 파라메타</param>
/// <param name="queryResultCode">조회 요청 결과를 코드값으로 정의하여 리턴</param>
/// <returns>queryResultCode = 0 : 명확한 오류 발생 , queryResultCode = 1 : 성공, queryResultCode =2 : 다시 조회</returns>
private WeXiaoData WeCahtQueryResult(Hashtable htRefSendData, ref int queryResultCode)
{
string resultXmlString = string.Empty;//조회 결과 xml
int iRet = WeChatQuery(htRefSendData, ref resultXmlString);
if (iRet != BaseCom.OK)
{
queryResultCode = 0;//오류 발생
}
bool isCheckSign = false;
WeXiaoData queryResult = new WeXiaoData();
queryResult.FromResponse(resultXmlString, ref isCheckSign);
if ( queryResult.IsKeyValue("return_code") && queryResult.GetValue("return_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS)
&& queryResult.IsKeyValue("result_code") && queryResult.GetValue("result_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS) )
{
#region trade_state
if (queryResult.IsKeyValue("trade_state"))
{
string trade_state = queryResult.GetValue("trade_state").ToString().ToUpper();
if (trade_state.Equals(WeXiaoConfig.SUCCESS))
{
queryResultCode = 1;//조회 성공
return queryResult;
}
else if (trade_state.Equals(WeXiaoConfig.USERPAYING) || trade_state.Equals(WeXiaoConfig.SYSTEMERROR) || trade_state.Equals(WeXiaoConfig.UNKNOWN))
{ //retry
queryResultCode = 2;//조회 결과 비밀번호 입력 대기중
return queryResult;
}
}
else
{
queryResultCode = 0;//오류 발생
}
#endregion
}
if (queryResult.IsKeyValue("err_code") && queryResult.GetValue("err_code").ToString().ToUpper().Equals("ORDERNOTEXIST"))
{
queryResultCode = 0;//오류 발생
}
else
{
queryResultCode = 2;//다시 조회 요청
}
return queryResult;
}
//위쳇 결제 조회 데이타
private int WeChatQuery(Hashtable htRefSendData, ref string resultXmlString)
{
WeXiaoData data = new WeXiaoData();
data.SetValue("mch_id", htRefSendData["mch_id"]);
data.SetValue("nonce_str", WeXiaoUtil.MakeNonceString());
data.SetValue("out_trade_no", htRefSendData["out_trade_no"].ToString());
//data.SetValue("transaction_id", transaction_id);
data.SetValue("sign", data.MakeSign());//맨 나중에
string xmlString = data.MakeSendXmlString();
//조회는 db log 는 남기지 않음
int iRet = m_cNetworkHttp.HttpPOST_SendReceive(WeXiaoConfig.MICROPAY_QUERY_URL, "text/xml", xmlString, ref resultXmlString);
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[WeChat Query SEND<>RECV:" + xmlString + resultXmlString);
return iRet;
}
#endregion
#region ,
/// <summary>
///
/// </summary>
/// <param name="sTradeDiv">결제/직전취소/망취소/반품 구분</param>
/// <param name="sPAY_WAY_CD"><결제 수단/param>
/// <param name="sPAY_DTL_CD_01">결제 상세 코드</param>
/// <param name="sVanCD">VAN Code</param>
/// <param name="sTrType"></param>
/// <param name="sInPutType">입력구분:사용 안함</param>
/// <param name="sInPutData">카드번호</param>
/// <param name="sInEncData">승인번호 : 사용 안함</param>
/// <param name="nPayAmt">대상금액</param>
/// <param name="sTransID">결제코드 (상가 주문 번호):사용 안함</param>
/// <param name="sOrdTransID">결제코드 (상가 주문 번호)-yyMMddHHmmssfff9</param>
/// <param name="sApprNo">승인번호(상가 주문 번호,yyMMddHHmmssfff9) : 사용 안 함</param>
/// <param name="sOrgPayID">원결제구분: 사용 안 함</param>
/// <param name="IsAppLog">DB 로그 남김 여부</param>
/// <param name="htRecvData"></param>
/// <returns></returns>
private string ExecuteXmlIrt_CanCel(string sTradeDiv, string sPAY_WAY_CD, string sPAY_DTL_CD_01, string sVanCD, string sTrType
, string sInPutData, double nPayAmt
, string sOrdTransID
, bool IsAppLog, ref Hashtable htRecvData) //, string sInPutType, string sInEncData, string sTransID, string sApprNo, string sOrgPayID
{
string sRet = UserCom.RST_ERR;
int iRet = BaseCom.NG;
try
{
//전문 송.수신
string stSendData = MakeWeChatReverseBodyData(sVanCD,sOrdTransID);
// 요청 - 승인로그 저장 (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
if (IsAppLog) m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "S", sInPutData, nPayAmt.ToString(), "", "", "", "", "", stSendData });
string sRespData = string.Empty;
WeXiaoData result = WeChatReverseResult("S", stSendData, ref sRespData, ref iRet);
//수신 처리
string sWriteRecvData = sRespData;// CmUtil.MakeLogDataToMask(false, sInEncData, sRespData);
#region
string return_code = string.Empty; string return_msg = string.Empty;
string result_code = string.Empty; string err_code = string.Empty; string err_code_des = string.Empty;
string recall = string.Empty;
if (result.IsKeyValue("return_code"))
{
#region
return_code = result.GetValue("return_code").ToString();
return_msg = result.IsKeyValue("return_msg") ? result.GetValue("return_msg").ToString() : "";
result_code = result.IsKeyValue("result_code") ? result.GetValue("result_code").ToString() : "";
err_code = result.IsKeyValue("err_code") ? result.GetValue("err_code").ToString() : "";
err_code_des = result.IsKeyValue("err_code_des") ? result.GetValue("err_code_des").ToString() : "";
recall = result.IsKeyValue("recall") ? result.GetValue("recall").ToString() : "";
#endregion
}
if (IsAppLog)
{
#region - DB
m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { m_cPayItem.PAY_WAY_CD, m_cPayItem.PAY_DTL_CD_01, sTrType, "R"
, sInPutData
, nPayAmt.ToString() // 결제 금액
, sOrdTransID // 승인 번호, 취소시에는 sTransID 와 동일값이 된다.
, DateTime.Now.ToString("yyyyMMdd")
, DateTime.Now.ToString("HHmmss")
, return_code+","+result_code+","+recall.ToUpper() //응답상태값
, "return_msg:"+return_msg+",err_code_des:"+err_code_des //응답메시지
, sWriteRecvData });
#endregion
}
#region
if (iRet != BaseCom.OK)
{
if (m_bErrMsgShow == true) WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0158));
return sRet;
}
bool isExecRecall = true;//재요청
string sErrorMessage = string.Empty;
if (string.IsNullOrEmpty(return_code))
{
sErrorMessage = "return_code Exception";
sRet = UserCom.RST_ERR;
isExecRecall = false;
}
else if (!return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS))//인터페이스 실패
{
sErrorMessage = return_msg;
sRet = UserCom.RST_ERR;
isExecRecall = false;
}
//인터페이스 성공, 비지니스 성공
else if (return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS) && result_code.ToUpper().Equals(WeXiaoConfig.SUCCESS) && recall.ToUpper().Equals("N"))
{
sRet = UserCom.RST_OK;
isExecRecall = false;
}
if (isExecRecall == false) // 바로 리턴
{
if (!string.IsNullOrEmpty(sErrorMessage) && sRet != UserCom.RST_OK && m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage);
return sRet;
}
#endregion
#endregion
if (recall.ToUpper().Equals("Y")) // 재요청
{
#region ( 30, 10)
//30초 동안 최대 10회 진행
int retryCount = 0;
int maxRetryCount = 10;
DateTime startTime = DateTime.Now;
TimeSpan durationSec = new TimeSpan(0, 0, 30);//30 초
//queryResultCode = 0;//조회 결과 , queryResultCode = 0 : 명확한 오류 발생으로 재조회 하지 않음 , queryResultCode = 1 : 성공, queryResultCode =2 : 다시 조회
while (startTime.Add(durationSec) > DateTime.Now && retryCount < maxRetryCount)
{
#region
retryCount++;
iRet = BaseCom.NG;
WeXiaoData recallResult = WeChatReverseResult("Q", stSendData, ref sRespData, ref iRet);
if (iRet != BaseCom.OK)
{
System.Threading.Thread.Sleep(2500);
continue; ;
}
if (recallResult.IsKeyValue("return_code") && !recallResult.GetValue("return_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS))
{
System.Threading.Thread.Sleep(2500);
continue; ;
}
else if (recallResult.IsKeyValue("result_code") && recallResult.GetValue("result_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS) && recallResult.GetValue("recall").ToString().ToUpper().Equals("Y"))
{
System.Threading.Thread.Sleep(2500);
continue; ;
}
else if (recallResult.IsKeyValue("result_code") && recallResult.GetValue("result_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS) && recallResult.GetValue("recall").ToString().ToUpper().Equals("N"))
{
break; //성공함
}
#endregion
}//반복 조회 끝
if (iRet == BaseCom.OK)
{
sRet = UserCom.RST_OK;
}
else
{
sRet = UserCom.RST_ERR;
}
#endregion
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[result colde, retry count:" + iRet.ToString() + "," + retryCount.ToString());
}
}
catch (Exception ex)
{
sRet = UserCom.RST_ERR;
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
//CmUtil.ZeroFillClear(ref sInEncData);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
private WeXiaoData WeChatReverseResult(string ApprLogTranType, string stSendData
, ref string sRespData
, ref int iRet)
{
if(ApprLogTranType == "Q")
{
//재조회 쿼리 여부 확인
}
WeXiaoData reverseResult = new WeXiaoData();
iRet = m_cNetworkHttp.HttpPOST_SendReceive(WeXiaoConfig.MICROPAY_REVERSE_URL, "text/xml", stSendData, ref sRespData);
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[WeChat Reverse SEND<>RECV:" + stSendData + sRespData);
if (iRet != BaseCom.OK)
{
return reverseResult;
}
string resultXmlString = sRespData;//조회 결과 xml
bool isCheckSign = false;
reverseResult.FromResponse(resultXmlString, ref isCheckSign);
return reverseResult;
}
private string MakeWeChatReverseBodyData(string sVanCD, string sOrdTransID)
{
string sApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.APPR_ID);//CAT ID(위쳇에서 발행한 점포고유코드)
WeXiaoData data = new WeXiaoData();
data.SetValue("mch_id", sApprID);//위쳇에 입점된 점포 코드
data.SetValue("nonce_str", WeXiaoUtil.MakeNonceString());
data.SetValue("out_trade_no", sOrdTransID);//随机生成商户退款单号
//data.SetValue("transaction_id", transaction_id);
data.SetValue("sign", data.MakeSign());//
return data.MakeSendXmlString();
}
#endregion
#region
private string ExecuteXmlIrt_Refund(string sTradeDiv, string sPAY_WAY_CD, string sPAY_DTL_CD_01, string sVanCD, string sTrType
, string sInPutType, string sInPutData, string sInEncData, double nPayAmt
, string sTransID, string sOrdTransID, string sApprNo, string sOrgPayID, ref Hashtable htRecvData)
{
string sRet = UserCom.RST_ERR;
int iRet = BaseCom.NG;
try
{
#region .,
// 전문 생성
string stSendData = MakeWeChatRefundBodyData(sVanCD, sApprNo, nPayAmt);//기존 거래 번호
// 요청 - 승인로그 저장 (판매구분, [0]결제수단, [1]결제상세코드, [2]전문구분, [3]요청구분, [4]카드번호, [5]결제금액, [6]승인번호, [7]승인일자, [8]승인시간, [9]응답상태값, [10]응답메시지, [11]전문)
m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "S", sInPutData, nPayAmt.ToString(), "", "", "", "", "", stSendData });
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[Xiao Wechat pay Refund send data:" + stSendData);
string sRespData = string.Empty;
iRet = m_cNetworkHttp.HttpPOST_SendReceive(WeXiaoConfig.MICROPAY_REFUND_URL, "text/xml", stSendData, ref sRespData);
//수신 로그 추가
m_cDataCommon.SetSaleApprLog(sTradeDiv, new string[] { sPAY_WAY_CD, sPAY_DTL_CD_01, sTrType, "R", sInPutData, nPayAmt.ToString(), sTransID, DateTime.Now.ToString("yyyyMMdd"), DateTime.Now.ToString("HHmmss"), "" , sRespData });
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[Xiao Wechat pay Refund receive data:" + sRespData);
if (iRet != BaseCom.OK)
{
if (m_bErrMsgShow == true) WinManager.ErrorMessage(MessageManager.GetErrorMessage(POS_MESSAGE.ERROR.MSG_0158));
return sRet;
}
#endregion
#region
//string sWriteRecvData = sRespData;// CmUtil.MakeLogDataToMask(false, sInEncData, sRespData);
string sErrorMessage = string.Empty;
bool isCheckSign = false;
WeXiaoData result = new WeXiaoData();
result.FromResponse(sRespData, ref htRecvData, ref isCheckSign);
string return_code = string.Empty; string return_msg = string.Empty;
string result_code = string.Empty; string err_code = string.Empty; string err_code_des = string.Empty;
if (result.IsKeyValue("return_code"))
{
#region
return_code = result.GetValue("return_code").ToString();
return_msg = result.IsKeyValue("return_msg") ? result.GetValue("return_msg").ToString() : "";
result_code = result.IsKeyValue("result_code") ? result.GetValue("result_code").ToString() : "";
err_code = result.IsKeyValue("err_code") ? result.GetValue("err_code").ToString() : "";
err_code_des = result.IsKeyValue("err_code_des") ? result.GetValue("err_code_des").ToString() : "";
#endregion
}
#endregion
#region return
if (string.IsNullOrEmpty(return_code))
{
sErrorMessage = "return_code Exception";
sRet = UserCom.RST_ERR;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage + "(" + return_code + ")");
return sRet;
}
if (!return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS))//인터페이스 실패
{
sErrorMessage = return_msg;
sRet = UserCom.RST_ERR;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage + "(" + return_code + ")");
return sRet;
}
//인터페이스 성공, 비지니스 성공
if (return_code.ToUpper().Equals(WeXiaoConfig.SUCCESS) && result_code.ToUpper().Equals(WeXiaoConfig.SUCCESS))
{
sRet = UserCom.RST_OK;
return sRet;
}
#endregion
//인터페이스 성공, 비지니스 실패 상세 정보
if (!err_code.ToUpper().Equals(WeXiaoConfig.USERPAYING) && !err_code.ToUpper().Equals(WeXiaoConfig.SYSTEMERROR) && !err_code.ToUpper().Equals(WeXiaoConfig.UNKNOWN))
{
#region
if (!err_code_des.Equals("")) sErrorMessage = err_code_des + " (err_code:" + err_code + ")";
else sErrorMessage = return_msg + " (return_code:" + return_code + ")";
sRet = UserCom.RST_ERR;
if (m_bErrMsgShow) WinManager.ErrorMessage(sErrorMessage);
return sRet;
#endregion
}
//##반품 조회 기능
if (err_code.ToUpper().Equals(WeXiaoConfig.USERPAYING) || err_code.ToUpper().Equals(WeXiaoConfig.SYSTEMERROR) || err_code.ToUpper().Equals(WeXiaoConfig.UNKNOWN))
{
#region
//30초 동안 최대 10회 진행
int retryCount = 0;
int maxRetryCount = 10;
DateTime startTime = DateTime.Now;
TimeSpan durationSec = new TimeSpan(0, 0, 30);//30 초
int queryResultCode = 0;//조회 결과 , queryResultCode = 0 : 명확한 오류 발생으로 재조회 하지 않음 , queryResultCode = 1 : 성공, queryResultCode =2 : 다시 조회
while (startTime.Add(durationSec) > DateTime.Now && retryCount < maxRetryCount)
{
retryCount++;
WeXiaoData resultWeChatQuery = WeCahtRefundQueryResult(sVanCD, sApprNo, ref queryResultCode);
if (queryResultCode == 1) //성공
{
break;
}
else if (queryResultCode == 2) //다시 조회 시도
{
System.Threading.Thread.Sleep(2500);
continue;
}
else // 명확한 오류
{
break;
}
}//while end
if (queryResultCode == 1)
{
sRet = UserCom.RST_OK;
}
else
{
sRet = UserCom.RST_ERR;
}
#endregion
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[wechat reufnd query result code, retry count ]:" + queryResultCode.ToString() + "," + retryCount.ToString());
}
}
catch (Exception ex)
{
sRet = UserCom.RST_ERR;
WinManager.ExceptionMessage(System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()", ex.Message);
UserLog.WriteLogFile(UserCom.LOG_ERROR,
UserCom.ERROR_LEVEL,
System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name, // Project Name (프로젝트명)
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + // Class Name (Class Name (클래스명))
System.Reflection.MethodBase.GetCurrentMethod().Name + "()", // Function Name (Function Name (함수명))
ex.ToString());
}
finally
{
//여전법 대응!
//////////////////////////////////////////////////////////////////////////////////
CmUtil.ZeroFillClear(ref sInPutData);
CmUtil.ZeroFillClear(ref sInEncData);
//////////////////////////////////////////////////////////////////////////////////
}
return sRet;
}
/// <summary>
/// 위쳇 영수증 반품 전문 데이타 생성
/// </summary>
/// <param name="sTransID">승인 번호</param>
/// <param name="nPayAmt">승인 금액</param>
/// <returns></returns>
public string MakeWeChatRefundBodyData(string sVanCD, string sApprNo, double nPayAmt)
{
int total_fee = 0; //결제할 금액
string sApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.APPR_ID);//CAT ID(위쳇에서 발행한 점포고유코드)
string out_refund_no = m_cPosStatus.Base.StoreNo + "_" + m_cTrnStatus.Head.OrgSaleDate + "_" + m_cTrnStatus.Head.OrgPosNo + "_" + m_cTrnStatus.Head.OrgTradeNo;
total_fee = (int)CmUtil.DoubleMultiplication(nPayAmt, 100);
WeXiaoData data = new WeXiaoData();
data.SetValue("mch_id", sApprID); ;//@@임시 "1485695332"
data.SetValue("nonce_str", WeXiaoUtil.MakeNonceString());
data.SetValue("total_fee", total_fee);//订单总金额
data.SetValue("refund_fee", total_fee);//退款金额
data.SetValue("out_trade_no", sApprNo);
data.SetValue("out_refund_no", out_refund_no);//随机生成商户退款单号 , CMP_CD ,STOR_CD ,SALE_DT ,POS_NO, TRADE_NO
//data.SetValue("op_user_id", "1485695332");//操作员,默认为商户号
data.SetValue("sign", data.MakeSign());//맨 나중에
return data.MakeSendXmlString();
}
/// <summary>
/// 위쳇 영수증 반품 조회 호출
/// </summary>
/// <param name="out_trade_no">승인 번호</param>
/// <param name="queryResultCode">조회 결과 코드</param>
/// <returns></returns>
private WeXiaoData WeCahtRefundQueryResult(string sVanCD, string out_trade_no, ref int queryResultCode)
{
string sApprID = PosMstManager.GetMstVan(sVanCD, PosMst.MST_VAN.DATA.APPR_ID);//CAT ID(위쳇에서 발행한 점포고유코드)
string resultXmlString = string.Empty;//조회 결과 xml
int iRet = WeChatRefundQuery(sApprID, out_trade_no, ref resultXmlString);
if (iRet != BaseCom.OK)
{
queryResultCode = 0;//오류 발생
}
bool isCheckSign = false;
WeXiaoData queryResult = new WeXiaoData();
queryResult.FromResponse(resultXmlString, ref isCheckSign);
if ( queryResult.IsKeyValue("return_code") && queryResult.GetValue("return_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS)
&& queryResult.IsKeyValue("result_code") && queryResult.GetValue("result_code").ToString().ToUpper().Equals(WeXiaoConfig.SUCCESS)
)
{
queryResultCode = 1;//조회 성공
return queryResult;
}
else
{
if (queryResult.IsKeyValue("err_code"))
{
#region
if (queryResult.GetValue("err_code").ToString().ToUpper().Equals(WeXiaoConfig.USERPAYING)
|| queryResult.GetValue("err_code").ToString().ToUpper().Equals(WeXiaoConfig.SYSTEMERROR)
|| queryResult.GetValue("err_code").ToString().ToUpper().Equals(WeXiaoConfig.UNKNOWN))
{
queryResultCode = 2;//조회 결과 비밀번호 입력 대기중
return queryResult;
}
else// if (result.IsKeyValue("err_code") && result.GetValue("err_code").ToString().ToUpper().Equals("ORDERNOTEXIST"))
{
queryResultCode = 0;//오류 발생
}
//else
//{
// queryResultCode = 2;//다시 조회 요청
//}
#endregion
}
else
{
queryResultCode = 0;//오류 발생
}
}
return queryResult;
}
/// <summary>
/// 위쳇 영수증 반품 조회
/// </summary>
/// <param name="sApprID">상점 cat id</param>
/// <param name="sTransID">승인 번호</param>
/// <param name="resultXmlString">응답 결과 xml</param>
/// <returns></returns>
private int WeChatRefundQuery(string sApprID, string sTransID, ref string resultXmlString)
{
WeXiaoData data = new WeXiaoData();
data.SetValue("mch_id", sApprID);
data.SetValue("nonce_str", WeXiaoUtil.MakeNonceString());
data.SetValue("out_trade_no", sTransID);
//data.SetValue("transaction_id", transaction_id);
data.SetValue("sign", data.MakeSign());//맨 나중에
string xmlString = data.MakeSendXmlString();
//조회는 db log 는 남기지 않음
int iRet = m_cNetworkHttp.HttpPOST_SendReceive(WeXiaoConfig.MICROPAY_REFUND_QUERY_URL, "text/xml", xmlString, ref resultXmlString);
UserLog.WriteLogFile(UserCom.LOG_SOCK, System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.Name,
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + "()",
"[WeChat Refund Query SEND<>RECV:" + xmlString + resultXmlString);
return iRet;
}
#endregion
}
#endregion Class WeChatPay_BaiRong End
#region Bai Rong
/// <summary>
/// Bai Rong 사와 통신 관련
/// </summary>
public class WeXiaoData
{
public WeXiaoData()
{
}
private SortedDictionary<string, object> dicValues = new SortedDictionary<string, object>();
public void SetValue(string key, object value)
{
dicValues[key] = value;
}
public object GetValue(string key)
{
object obj = null;
dicValues.TryGetValue(key, out obj);
return obj;
}
/// <summary>
/// Dictionary 에 해당키에 값이 있는지 체크, key 는 있지만 값이 없을 경우에는 false 리턴
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public bool IsKeyValue(string key) //IsSet()
{
object obj = null;
dicValues.TryGetValue(key, out obj);
if (obj != null) return true; // key 는 있지만 값이 없을 수 도 있음.
else return false;
//if (dicValues.ContainsKey(key)) return true;// key 가 있다고 무조건 return 은 아님
//else return false;
}
/// <summary>
/// sign 값 만듬
/// </summary>
/// <returns></returns>
public string MakeSign()
{
string str = MakeToUrlParams() + "&key=" + WeXiaoConfig.KEY;
var md5 = MD5.Create();
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
return sb.ToString().ToUpper();
}
/// <summary>
/// url GET 형식으로 &key=value 연결
/// </summary>
/// <returns></returns>
private string MakeToUrlParams()
{
StringBuilder sb = new StringBuilder();
string buff = "";
foreach (KeyValuePair<string, object> dic in dicValues)
{
if (dic.Value == null) //"" 과 다름
{
throw new Exception("key values null exception");
}
else
{
if (!dic.Key.ToLower().Equals("sign") && !string.IsNullOrEmpty(dic.Value.ToString()))
{
//buff += dic.Key + "=" + dic.Value + "&";
sb.Append(dic.Key);
sb.Append("=");
sb.Append(dic.Value);
sb.Append("&");
}
}
}
buff = sb.ToString();
buff = buff.Trim('&');
return buff;
}
/// <summary>
/// 전송할 값들은 xml string 로 만듬
/// </summary>
/// <returns></returns>
public string MakeSendXmlString()
{
if (dicValues.Count == 0)
{
throw new Exception("key values count 0");
}
StringBuilder sb = new StringBuilder();
sb.Append("<xml>");
foreach (KeyValuePair<string, object> dic in dicValues)
{
if (dic.Value == null)
{
throw new Exception("key values null exception");
}
if (dic.Value.GetType() == typeof(int))
{
sb.Append("<"); sb.Append(dic.Key); sb.Append(">");
sb.Append(dic.Value);
sb.Append("</"); sb.Append(dic.Key); sb.Append(">");
}
else if (dic.Value.GetType() == typeof(string))
{
sb.Append("<"); sb.Append(dic.Key); sb.Append(">");
sb.Append("<![CDATA["); sb.Append(dic.Value); sb.Append("]]>");
sb.Append("</"); sb.Append(dic.Key); sb.Append(">");
}
else
{
throw new Exception("key values type exception");
}
}
sb.Append("</xml>");
return sb.ToString().Trim();
}
public SortedDictionary<string, object> FromResponse(string responseXml, ref bool isCheckSign)
{
if (string.IsNullOrEmpty(responseXml))
{
throw new Exception("response xml empty");
}
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(responseXml);
XmlNode xNode = xDoc.FirstChild;//<xml>
XmlNodeList xNodes = xNode.ChildNodes;
foreach (XmlNode xn in xNodes)
{
XmlElement xEle = (XmlElement)xn;
dicValues[xEle.Name] = xEle.InnerText;
}
try
{
if (dicValues["return_code"] != "SUCCESS")
{
return dicValues;
}
isCheckSign = CheckSign();
}
catch (Exception ex)
{
throw;
}
return dicValues;
}
public SortedDictionary<string, object> FromResponse(string responseXml, ref Hashtable htRecvData, ref bool isCheckSign)
{
if (string.IsNullOrEmpty(responseXml))
{
throw new Exception("response xml empty");
}
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(responseXml);
XmlNode xNode = xDoc.FirstChild;//<xml>
XmlNodeList xNodes = xNode.ChildNodes;
foreach (XmlNode xn in xNodes)
{
XmlElement xEle = (XmlElement)xn;
dicValues[xEle.Name] = xEle.InnerText;
htRecvData.Add(xEle.Name, xEle.InnerText);
}
try
{
if (dicValues["return_code"] != "SUCCESS")
{
return dicValues;
}
isCheckSign = CheckSign();
}
catch (Exception ex)
{
throw;
}
return dicValues;
}
private bool CheckSign()
{
if (!IsKeyValue("sign"))
{
throw new Exception("response no sign key");
}
else if (GetValue("sign") == null || GetValue("sign").ToString() == "")
{
throw new Exception("response no sign ");
}
string responseSign = GetValue("sign").ToString();
string calSign = MakeSign();
if (calSign == responseSign)
{
return true;
}
else
{
return false;
}
}
}
public class WeXiaoConfig
{
public const string SUCCESS = "SUCCESS";
public const string FAIL = "FAIL";
public const string SYSTEMERROR = "SYSTEMERROR";
public const string UNKNOWN = "UNKNOWN";
public const string USERPAYING = "USERPAYING";
//public const string MCH_ID = "1485695332";
public const string KEY = "800bed2b96a3006972d37ab9237104a8";
public const string MICROPAY_URL = "https://spc.bryzf.com/api/offline_micropay";//위쳇 페이
public const string MICROPAY_QUERY_URL = "https://spc.bryzf.com/api/offline_query_order";//위쳇 페이 결제 요청 중 조회
public const string MICROPAY_REVERSE_URL = "https://spc.bryzf.com/api/offline_reverse";//위쳇 페이 즉시 취소(망취소)
public const string MICROPAY_REFUND_URL = "https://spc.bryzf.com/api/offline_refund";//위쳇 페이 영수증 반품
public const string MICROPAY_REFUND_QUERY_URL = "https://spc.bryzf.com/api/offline_refund_query";//위쳇 페이 영수증 반품 조회
public const string GIFTCARD_URL = "https://spc.bryzf.com/api/consume";
public const string GIFTCARD_QUERY_URL = "https://spc.bryzf.com/api/check";
}
public class WeXiaoUtil
{
/// <summary>
/// 랜덤 문자열 32 자리
/// </summary>
/// <returns></returns>
public static string MakeNonceString()
{
return Guid.NewGuid().ToString().Replace("-", "");
}
public static string GetPOS_IP()
{
//xp 에서는 다른 결과 일 수도 있음
try
{
IPHostEntry host = Dns.GetHostByName(Dns.GetHostName());
return host.AddressList[0].ToString();
}
catch(Exception )
{
return "127.0.0.1";
}
}
}
#endregion
}