489 lines
19 KiB
C#
489 lines
19 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web;
|
||
|
||
namespace ApplyTest.app
|
||
{
|
||
public class Class1
|
||
{
|
||
//配置信息
|
||
//服务器地址
|
||
public const string YZG_CONFIG_HOST = "http://118.178.235.230/open-api/";
|
||
//合作方编码
|
||
public const string YZG_CONFIG_APPID = "G0000032";
|
||
public const string YZG_CONFIG_KEY = "debf3201adba5af8615d4b4d425c6656";
|
||
public Class1()
|
||
{
|
||
//
|
||
// TODO: 在此处添加构造函数逻辑
|
||
//
|
||
}
|
||
|
||
//获取传入的参数,并将参数按键值对组成新的字符串
|
||
//测试省份获取接口,无传入参数,返回JSON字符串
|
||
public static string getProvinceList()
|
||
{
|
||
|
||
//无传入参数,直接将appId与key按键值对传入接口
|
||
//调用函数得到键值对组成的字符串
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
string param = createStr(dic);
|
||
//调用传参函数
|
||
string result = HttpPost(param, "card/getProvince");
|
||
return result;
|
||
}
|
||
|
||
//城市列表接口测试
|
||
//传入参数:@provinceCode:省份编号
|
||
public static string getCityList(string provinceCode)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["provinceCode"] = provinceCode;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "card/getCity");
|
||
return result;
|
||
}
|
||
|
||
//获取卡信息接口测试
|
||
//传入参数
|
||
//@cardNo:卡号
|
||
//返回JSON字符串
|
||
public static string getCardInfo(string cardNo)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["cardNo"] = cardNo;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "card/getCardInfo");
|
||
return result;
|
||
}
|
||
|
||
//获取卡所在支行信息接口测试
|
||
//传入参数
|
||
//@cardNo:卡号
|
||
//@city:城市名
|
||
//@keyword:关键字
|
||
//返回JSON字符串
|
||
public static string getCardSubBankInfo(string cardNo, string city, string keyword)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["city"] = city;
|
||
dic["cardNo"] = cardNo;
|
||
dic["keyword"] = keyword;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "card/getCardSubBankInfo");
|
||
return result;
|
||
}
|
||
|
||
//商户注册接口测试
|
||
//传入参数
|
||
//@merchantName:商户名称
|
||
//@address:商家地址
|
||
//@mobile:商家手机号
|
||
//@applicantName:商家名称
|
||
//@applicantIdno:商家身份证号
|
||
//@notifyUrl:商家审核状态回调接口
|
||
//@businessCatagory1:业务类别1
|
||
//@businessCatagory2:业务类别2
|
||
//@mcc:MCC
|
||
//返回JSON字符串
|
||
public static string add(string merchantName, string address, string mobile, string applicantName,
|
||
string applicantIdno, string notifyUrl, string businessCatagory1, string businessCatagory2, string mcc)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["merchantName"] = merchantName;
|
||
dic["address"] = address;
|
||
dic["mobile"] = mobile;
|
||
dic["applicantName"] = applicantName;
|
||
dic["applicantIdno"] = applicantIdno;
|
||
dic["notifyUrl"] = notifyUrl;
|
||
dic["businessCatagory1"] = businessCatagory1;
|
||
dic["businessCatagory2"] = businessCatagory2;
|
||
dic["mcc"] = mcc;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "storeInfo/add");
|
||
return result;
|
||
}
|
||
|
||
//商户基本信息更新接口测试
|
||
//传入参数
|
||
//@memberCode:商户编号
|
||
//@merchantName:商户名称
|
||
//@address:商家地址
|
||
//@mobile:商家手机号
|
||
//@applicantName:商家姓名
|
||
//@notifyUrl:商家审核状态回调接口
|
||
//@applicantIdno:商家身份证号
|
||
//@businessCatagory1:业务类别1
|
||
//@businessCatagory2:业务类别2
|
||
//@mcc:MCC
|
||
//返回JSON字符串
|
||
public static string modify(string memberCode, string merchantName,
|
||
string address, string mobile, string applicantName, string notifyUrl,
|
||
string applicantIdno, string businessCatagory1, string businessCatagory2, string mcc)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["memberCode"] = memberCode;
|
||
dic["merchantName"] = merchantName;
|
||
dic["address"] = address;
|
||
dic["mobile"] = mobile;
|
||
dic["applicantName"] = applicantName;
|
||
dic["applicantIdno"] = applicantIdno;
|
||
dic["notifyUrl"] = notifyUrl;
|
||
dic["businessCatagory1"] = businessCatagory1;
|
||
dic["businessCatagory2"] = businessCatagory2;
|
||
dic["mcc"] = mcc;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "storeInfo/modify");
|
||
return result;
|
||
}
|
||
|
||
//设置申请人结算卡信息接口测试
|
||
//传入参数
|
||
//@name:商户名称
|
||
//@memberCode:商家编号
|
||
//@mobile:手机号
|
||
//@branchName:支行名称
|
||
//@branchNo:支行号
|
||
//@cardNo:卡号
|
||
//@bankName:银行名
|
||
//返回JSON字符串
|
||
public static string setCard(string name, string memberCode, string mobile,
|
||
string branchName, string branchNo, string cardNo, string bankName)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["name"] = name;
|
||
dic["memberCode"] = memberCode;
|
||
dic["mobile"] = mobile;
|
||
dic["branchName"] = branchName;
|
||
dic["branchNo"] = branchNo;
|
||
dic["cardNo"] = cardNo;
|
||
dic["bankName"] = bankName;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "applicant/setCard");
|
||
return result;
|
||
}
|
||
|
||
//商户绑定接口测试
|
||
//传入参数
|
||
//@memberCode:
|
||
//@partnerUser:合作商号
|
||
//返回JSON字符串
|
||
public static string band(string memberCode, string partnerUser)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["memberCode"] = memberCode;
|
||
dic["partnerUser"] = partnerUser;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "store/band");
|
||
return result;
|
||
}
|
||
|
||
//交易订单详情查询接口测试
|
||
//传入参数
|
||
//@orderNo:订单号
|
||
//@memberCode:商家编号
|
||
//返回JSON字符串
|
||
public static string detail(string orderNo, string memberCode)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["orderNo"] = orderNo;
|
||
dic["memberCode"] = memberCode;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "bill/detail");
|
||
return result;
|
||
}
|
||
|
||
//交易记录列表接口测试
|
||
//传入参数
|
||
//@memberCode:商家编号
|
||
//@start:起始时间
|
||
//@end:结束时间
|
||
//@page:页索引号
|
||
//@rows:行数
|
||
//返回JSON字符串
|
||
public static string lists(string memberCode, string start, string end, string page, string rows)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["memberCode"] = memberCode;
|
||
dic["start"] = start;
|
||
dic["end"] = end;
|
||
dic["page"] = page;
|
||
dic["rows"] = rows;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "bill/lists");
|
||
return result;
|
||
}
|
||
|
||
|
||
//交易支付接口测试
|
||
//商家扫用户支付二维码
|
||
//传入参数
|
||
//@type:wechat或alipay,通过get方式传递
|
||
//@discountAmt:优惠金额
|
||
//@memberCode:商家编号
|
||
//@notifyUrl:交易结果通知接口URL
|
||
//@orderNo:外部订单号
|
||
//@qrcode:用户支付码
|
||
//@subject:交易对象
|
||
//@transAmt:实收金额
|
||
public static string merchantscan(string discountAmt, string memberCode, string notifyUrl,
|
||
string orderNo, string qrcode, string subject, string transAmt)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["discountAmt"] = discountAmt;
|
||
dic["memberCode"] = memberCode;
|
||
dic["notifyUrl"] = notifyUrl;
|
||
dic["orderNo"] = orderNo;
|
||
dic["qrcode"] = qrcode;
|
||
dic["subject"] = subject;
|
||
dic["transAmt"] = transAmt;
|
||
string param = createStr(dic);
|
||
string result = "";
|
||
if (qrcode.Substring(0, 1) == "1")
|
||
{
|
||
result = HttpPost(param, "unionpay/merchantscan/type/wechat");
|
||
}
|
||
else
|
||
{
|
||
result = HttpPost(param, "unionpay/merchantscan/type/alipay");
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//网页支付
|
||
//@type:wechat或alipay,通过get方式传递
|
||
//@discountAmt:优惠金额
|
||
//@memberCode:商家编号
|
||
//@notifyUrl:交易结果通知接口URL
|
||
//@orderNo:外部订单号
|
||
//@subject:交易对象
|
||
//@transAmt:实收金额
|
||
//@userid:用户支付userid
|
||
public static string webpay(string type, string discountAmt, string memberCode,
|
||
string notifyUrl, string orderNo, string subject, string transAmt, string userid)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["discountAmt"] = discountAmt;
|
||
dic["memberCode"] = memberCode;
|
||
dic["notifyUrl"] = notifyUrl;
|
||
dic["orderNo"] = orderNo;
|
||
dic["subject"] = subject;
|
||
dic["transAmt"] = transAmt;
|
||
dic["userid"] = userid;
|
||
string param = createStr(dic);
|
||
string result = "";
|
||
if (type == "wechat" || type == "alipay")
|
||
{
|
||
result = HttpPost(param, "unionpay/webpay/type/" + type);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//用户扫商家支付二维码
|
||
//@type:wechat或alipay,通过get方式传递
|
||
//@discountAmt:优惠金额
|
||
//@memberCode:商家编号
|
||
//@notifyUrl:交易结果通知接口URL
|
||
//@orderNo:外部订单号
|
||
//@subject:交易对象
|
||
//@transAmt:实收金额
|
||
//返回JSON字符串
|
||
public static string customerscan(string type, string discountAmt, string memberCode,
|
||
string notifyUrl, string orderNo, string subject, string transAmt)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["discountAmt"] = discountAmt;
|
||
dic["memberCode"] = memberCode;
|
||
dic["notifyUrl"] = notifyUrl;
|
||
dic["orderNo"] = orderNo;
|
||
dic["subject"] = subject;
|
||
dic["transAmt"] = transAmt;
|
||
string param = createStr(dic);
|
||
string result = "";
|
||
if (type == "wechat" || type == "alipay")
|
||
{
|
||
result = HttpPost(param, "unionpay/customerscan/type/" + type);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
//MCC码列表查询接口测试
|
||
//传入参数:无
|
||
//返回JSON字符串
|
||
public static string mcclists()
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "mcc/lists");
|
||
return result;
|
||
}
|
||
|
||
//商户一级类别列表查询接口测试
|
||
//传入参数:无
|
||
//返回JSON字符串
|
||
public static string level1()
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "mcc/level1");
|
||
return result;
|
||
}
|
||
|
||
//商户二级类别列表查询接口测试
|
||
//传入参数:
|
||
//@level1Id:一级列表id
|
||
public static string level2(string level1Id)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["level1Id"] = level1Id;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "mcc/level2");
|
||
return result;
|
||
}
|
||
|
||
//图片上传接口测试
|
||
//传入参数:
|
||
//@memberCode:商家编号
|
||
//@storeInnerImageUrl:商家内部照号URL
|
||
//@storeBankCardImageUrl:银行卡照片URL
|
||
//@storeBusinessImageUrl:营业执照URL
|
||
//@idCardFontImageUrl:身份证正面照URL
|
||
//@idCardBackImageUrl:身份证反面照URL
|
||
//@holdCardImageUrl:手持身份证半身照URL
|
||
//@storeImageUrl:申请人与门店合照URL
|
||
//返回JSON字符串
|
||
public static string imageUpload(string memberCode, string storeInnerImageUrl, string storeBankCardImageUrl,
|
||
string storeBusinessImageUrl, string idCardFontImageUrl, string idCardBackImageUrl, string holdCardImageUrl, string storeImageUrl)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["memberCode"] = memberCode;
|
||
dic["storeInnerImageUrl"] = storeInnerImageUrl;
|
||
dic["storeBankCardImageUrl"] = storeBankCardImageUrl;
|
||
dic["storeBusinessImageUrl"] = storeBusinessImageUrl;
|
||
dic["idCardFontImageUrl"] = idCardFontImageUrl;
|
||
dic["idCardBackImageUrl"] = idCardBackImageUrl;
|
||
dic["holdCardImageUrl"] = holdCardImageUrl;
|
||
dic["storeImageUrl"] = storeImageUrl;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "storeInfo/imageUpload");
|
||
return result;
|
||
}
|
||
|
||
//商家信息获取接口测试
|
||
//传入参数:
|
||
//@memberCode:商家编号
|
||
//返回JSON字符串
|
||
public static string get(string memberCode)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["memberCode"] = memberCode;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "storeInfo/get");
|
||
return result;
|
||
}
|
||
|
||
//退款接口测试
|
||
//传入参数:
|
||
//@authcode:商户订单号
|
||
//@memberCode:商家编号
|
||
//返回JSON字符串
|
||
public static string refund(string authcode, string memberCode)
|
||
{
|
||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||
dic["authcode"] = authcode;
|
||
dic["memberCode"] = memberCode;
|
||
string param = createStr(dic);
|
||
string result = HttpPost(param, "refund/authcode");
|
||
return result;
|
||
}
|
||
|
||
/********************************************************************************************************************/
|
||
public static string HttpPost(string str, string method)
|
||
{
|
||
try
|
||
{
|
||
System.Net.CookieContainer cookieContainer = new System.Net.CookieContainer();
|
||
byte[] postBytes = System.Text.Encoding.ASCII.GetBytes(str);
|
||
// 设置提交的相关参数
|
||
System.Net.HttpWebRequest request = System.Net.WebRequest.Create(YZG_CONFIG_HOST + method) as System.Net.HttpWebRequest;
|
||
request.Method = "POST";
|
||
request.KeepAlive = false;
|
||
request.ContentType = "application/x-www-form-urlencoded";
|
||
request.CookieContainer = cookieContainer;
|
||
request.ContentLength = postBytes.Length;
|
||
|
||
using (System.IO.Stream reqStream = request.GetRequestStream())
|
||
{
|
||
reqStream.Write(postBytes, 0, postBytes.Length);
|
||
}
|
||
using (System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse)
|
||
{
|
||
//在这里对接收到的页面内容进行处理
|
||
//直到request.GetResponse()程序才开始向目标网页发送post请求
|
||
System.IO.Stream responseStream = response.GetResponseStream();
|
||
System.IO.StreamReader reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
|
||
string val = reader.ReadToEnd();
|
||
return val;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ex.ToString();
|
||
}
|
||
}
|
||
|
||
//创建md5 32位小写加密
|
||
public static string createMD5(string text)
|
||
{
|
||
var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||
//换成utf8后对于中文加密也适用
|
||
byte[] output = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text));
|
||
string pass2md5 = BitConverter.ToString(output).Replace("-", "");
|
||
pass2md5 = pass2md5.ToLower();
|
||
return pass2md5;
|
||
}
|
||
|
||
//创建传入参数的键值对形式的字符串
|
||
//若传入参数为空,则字符串为appId=xxxxx&key=xxxxx
|
||
public static string createStr(Dictionary<string, string> dic)
|
||
{
|
||
//设置默认编码方式为utf-8
|
||
System.Text.Encoding myEncoding = System.Text.Encoding.GetEncoding("utf-8");
|
||
string s = "", tests = "";
|
||
//判断是否有值
|
||
//如果为空,则只需加入appId和key
|
||
if (dic.Count == 0)
|
||
{
|
||
s = "appId=" + YZG_CONFIG_APPID + "&key=" + YZG_CONFIG_KEY;
|
||
tests = s;
|
||
}
|
||
else //若不为空,则将参数按键值对排最后加上appId和key
|
||
{
|
||
//对传入参数按照键名升序排序
|
||
dic = (from entry in dic orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
|
||
foreach (string keys in dic.Keys)
|
||
{
|
||
//判断对应键值是否为空,为空则不参与签名
|
||
if (dic[keys] != "")
|
||
{
|
||
tests += keys + "=" + dic[keys] + "&";
|
||
}
|
||
//若用此字符串进行md5加密则结果跟php的md5加密不同
|
||
s += HttpUtility.UrlEncode(keys, myEncoding) + "=" + HttpUtility.UrlEncode(dic[keys], myEncoding) + "&";
|
||
|
||
|
||
}
|
||
s += "appId=" + YZG_CONFIG_APPID + "&key=" + YZG_CONFIG_KEY;
|
||
tests += "appId=" + YZG_CONFIG_APPID + "&key=" + YZG_CONFIG_KEY;
|
||
//去掉最后一个转义符&
|
||
//s = s.Substring(0, s.Length - 1);
|
||
}
|
||
|
||
//调用md5生成签名
|
||
dic["signature"] = createMD5(tests);
|
||
s += "&" + "signature" + "=" + dic["signature"];
|
||
return s;
|
||
}
|
||
}
|
||
} |