public static string ApplyEnter(string Data) {
if (string.IsNullOrWhiteSpace(Data)) return ProtocolManager.GetPackage(PackageReturnCode.Fail, "属性不能为空!");
else {
//遍历weixin对象
ViewWeixinApplyment weixinApplyment = JsonConvert.DeserializeObject<ViewWeixinApplyment>(Data);
weixinApplyment.version = "3.0";
weixinApplyment.cert_sn = weixinConfig.serial_no;
weixinApplyment.mch_id = weixinConfig.MchID;
weixinApplyment.nonce_str = Guid.NewGuid().ToString().Replace("-", "");
weixinApplyment.sign_type = "HMAC-SHA256";
weixinApplyment.sign = string.Empty;
weixinApplyment.id_card_valid_time = HttpUtility.UrlDecode(weixinApplyment.id_card_valid_time);
//业务申请编号
weixinApplyment.business_code = Guid.NewGuid().ToString().Replace("-", "");
ViewWeixinApplyment cloneweixinApplyment = weixinApplyment;//存入数据库对象 不加密
//检查参数
if (!WeixinHhelper.AccountNumberIsSupport(weixinApplyment.account_number)) return ProtocolManager.GetPackage(PackageReturnCode.Fail, "银行卡不符合规范!");
//铭感信息加密
weixinApplyment.id_card_name = WeixinHhelper.InfoEncryption( weixinApplyment.id_card_name);
weixinApplyment.id_card_number = WeixinHhelper.InfoEncryption(weixinApplyment.id_card_number);
weixinApplyment.account_name = WeixinHhelper.InfoEncryption(weixinApplyment.account_name);
weixinApplyment.account_number = WeixinHhelper.InfoEncryption(weixinApplyment.account_number);
weixinApplyment.contact = WeixinHhelper.InfoEncryption(weixinApplyment.contact);
weixinApplyment.contact_phone = WeixinHhelper.InfoEncryption(weixinApplyment.contact_phone);
weixinApplyment.contact_email = string.IsNullOrWhiteSpace(weixinApplyment.contact_email)?"" : WeixinHhelper.InfoEncryption(weixinApplyment.contact_email);
Type type = weixinApplyment.GetType();
PropertyInfo [] propertyInfos= type.GetProperties();
WxPayDataToXiaoWei wxPayDataToXiaoWei = new WxPayDataToXiaoWei();
WeixinApplyment _DbWeixinApplyment = new WeixinApplyment();
foreach (PropertyInfo item in propertyInfos)
{
if (item.Name!="sign")wxPayDataToXiaoWei.SetValue(item.Name,item.GetValue(weixinApplyment));
}
wxPayDataToXiaoWei.SetValue("sign", wxPayDataToXiaoWei.MakeSign(weixinConfig.Key));
string xml = wxPayDataToXiaoWei.ToXml();
//给db赋值
Type dbWeixinApplymentType = cloneweixinApplyment.GetType();
PropertyInfo[] DbpropertyInfos = dbWeixinApplymentType.GetProperties();
foreach (PropertyInfo item in DbpropertyInfos)
{
//给db赋值
_DbWeixinApplyment.GetType().GetProperty(item.Name).SetValue(_DbWeixinApplyment, item.GetValue(cloneweixinApplyment));
}
string url = "https://api.mch.weixin.qq.com/applyment/micro/submit";
int timeOut = 10;
string response = WeixinXiaoweiService.Post(xml, url, true,true, timeOut);
_DbWeixinApplyment.sign = wxPayDataToXiaoWei.GetValue("sign").ToString();
wxPayDataToXiaoWei.FromXml(response);
if (wxPayDataToXiaoWei.GetValue("return_code").ToString() == "SUCCESS"&& wxPayDataToXiaoWei.GetValue("result_code").ToString() == "SUCCESS")
{
//申请成功
var applyment_id = wxPayDataToXiaoWei.GetValue("applyment_id").ToString();
_DbWeixinApplyment.serial_no = weixinConfig.serial_no;
_DbWeixinApplyment.encrypt_certificate = JsonConvert.SerializeObject(weixinConfig.encrypt_certificate);
_DbWeixinApplyment.applyment_id = applyment_id;
_DbWeixinApplyment.CreateTime = DateTime.Now;
if (!ConfigDbTable.DbWeixinApplyment.DbBase.Insert<WeixinApplyment>(_DbWeixinApplyment))
return ProtocolManager.GetPackage(Resource.CodeFail, "数据添加失败!");
}
return ProtocolManager.GetPackage(PackageReturnCode.OK, response);
}
}