代码拉取完成,页面将自动刷新
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
namespace HIS.EHC
{
public class Helper
{
/// <summary>
/// 电子建卡服务地址
/// </summary>
//static string url = "http://hefei12320.com:8070/ehcService/gateway.do";
static string url = "http://11.103.9.9/ehcService/gateway.do";
/// <summary>
/// Post数据
/// </summary>
/// <param name="strUrl"></param>
/// <param name="indata"></param>
/// <param name="outdata"></param>
/// <returns></returns>
[DllImport("VirtualCardChk.dll")]
public static extern IntPtr VirtualCardTrans(string strUrl, string indata, ref byte outdata);
/// <summary>
/// 打印电子健康卡静态二维码
/// </summary>
/// <param name="ehealthid"></param>
/// <param name="cardNo"></param>
/// <param name="name"></param>
/// <returns></returns>
[DllImport("VirtualCardChk.dll")]
public static extern int EhealthID_Print(string ehealthid, string cardNo, string name);
/// <summary>
/// 卡管控制分屏显示,支付分屏是使用payclinet.ini控制
/// </summary>
/// <param name="mode"></param>
/// <returns></returns>
[DllImport("VirtualCardChk.dll")]
public static extern int Set_QRflow_Mode(int mode);
/// <summary>
/// 支付、退费、查询状态,一码付接口
/// </summary>
/// <param name="indata"></param>
/// <param name="outdata"></param>
/// <returns></returns>
[DllImport("payclient.dll")]
public static extern IntPtr payTrans(string indata, ref byte outdata);
/// <summary>
///
/// </summary>
/// <param name="indata"></param>
/// <param name="outdata"></param>
/// <returns></returns>
[DllImport("payclient.dll")]
public static extern IntPtr showTrans(string indata, ref byte outdata);
/// <summary>
/// 公众号消息推送
/// </summary>
/// <param name="url"></param>
/// <param name="indata"></param>
/// <param name="outdata"></param>
/// <returns></returns>
[DllImport("onepush.dll")]
public static extern string TransPush(string url, string indata, StringBuilder outdata);
public static bool PayInitEnvironment()
{
//string url = @"http://120.42.37.94:1301/onepay-web/oneweb/oneapi";
string url = @"http://11.103.9.9/onepay-web/oneweb/oneapi";//沂水环境
string appid = "1DNUJKJV00000100007F0000F0308269";
string appsec = "1DNUJKJUP00U29CDA8C0000050729D7A";
string indata = "{\"transType\":\"hop.trade.setinfo\",\"param\":{\"serveraddr\":\"" + url + "\",\"appid\":\"" + appid + "\",\"appsecret\":\"" + appsec + "\"}}";
SaveLog("设置服务参数入参:" + indata);
Byte[] outdata = new Byte[2048];
IntPtr a = payTrans(indata, ref outdata[0]);
string strGet = System.Text.Encoding.Default.GetString(outdata, 0, outdata.Length);
string strRet = Marshal.PtrToStringAnsi(a);
string outstring = strRet + "\r\n" + strGet.TrimEnd('\0');
SaveLog("设置服务参数出参:" + outstring);
if (Marshal.PtrToStringAnsi(a) == "000000")
{
MessageBox.Show(outstring);
return true;
}
else
{
MessageBox.Show(outstring + "\r\n" + "检查服务参数信息");
return false;
}
}
public static string Pay(string indata)
{
SaveLog("交易入参:" + indata);
Byte[] outdata = new Byte[2048];
IntPtr a = payTrans(indata, ref outdata[0]);
string strGet = System.Text.Encoding.Default.GetString(outdata, 0, outdata.Length);
string strRet = Marshal.PtrToStringAnsi(a);
string outstring = strRet + "\r\n" + strGet.TrimEnd('\0');
SaveLog("交易出参:" + outstring);
return outstring;
}
public static string VirtualCardTrans(string indata)
{
//var jsonObjin = JsonConvert.DeserializeObject(indata);
SaveLog("VirtualCardTrans入参:" + "url:" + url + "\r\n" + "indata:" + indata.ToString());
Byte[] outdata = new Byte[2048];
IntPtr a = Helper.VirtualCardTrans(url, indata, ref outdata[0]);
string strGet = System.Text.Encoding.Default.GetString(outdata, 0, outdata.Length);
string strRet = Marshal.PtrToStringAnsi(a);
return strRet + "\n" + strGet.TrimEnd('\0');
}
public static JObject CardTrans(string app_id,string key,string method,JObject paraobj)
{
try
{
string cardurl = "http://11.103.9.9/ehcService/gateway.do"; // 可按系统配置赋值
if (app_id == "")
{
app_id = "1BQA48ETK000A718A8C000001FFAA482"; // 可按系统配置赋值
}
if (key == "")
{
key = "1BQA48ETK001A718A8C00000FE996B9B"; // 可按系统配置赋值
}
// 请求头
JObject input = new JObject();
input["app_id"] = app_id;
input["term_id"] = "35020010001"; // 可按系统配置赋值
input["method"] = method; // *** 根据具体调用接口入参 ***
input["timestamp"] = DateTime.Now.ToString("yyyyMMddHHmmss");
input["sign_type"] = "SM3"; // 固定,支持MD5\SM3,SDK内部会自动根据该算法计算sign
input["version"] = "X.M.0.1"; // 固定
input["enc_type"] = "SM4"; // 固定,支持AES\SM4,SDK内部会自动根据该算法加密
// 业务参数
input["biz_content"] = JsonConvert.SerializeObject(paraobj);// JsonConvert.SerializeObject(paraobj);
string indata = Newtonsoft.Json.JsonConvert.SerializeObject(input);
SaveLog("注册电子健康卡入参:" + "url:" + cardurl + "\r\n" + "indata:" + indata.ToString());
Byte[] outdata = new Byte[2048];
IntPtr a = Helper.VirtualCardTrans(cardurl, indata, ref outdata[0]);
string strGet = System.Text.Encoding.Default.GetString(outdata, 0, outdata.Length);
string strRet = Marshal.PtrToStringAnsi(a);
JObject strGetout = JsonConvert.DeserializeObject<JObject>(strGet.TrimEnd('\0').ToString());
return strGetout;
}
catch (Exception ex)
{
JObject output = new JObject();
output["ret_code"] = "-9";
output["ret_msg"] = ex.Message;
return output;
}
//JObject output = new JObject();
//output["returncode"] = strRet;
//output["respMsg"]=
//return strRet + "\n" + strGet.TrimEnd('\0');
}
//保存日志
public static void SaveLog(string s)
{
try
{
string fileFolder = AppDomain.CurrentDomain.BaseDirectory.ToString() + "log";
if (!Directory.Exists(fileFolder))
{
Directory.CreateDirectory(fileFolder);
}
string filePath = fileFolder + "\\" + GetLogfile();
FileStream fs;
if (!File.Exists(filePath))
{
fs = File.Create(filePath);
}
else
{
fs = File.Open(filePath, FileMode.Append);
}
string strToWrite = "\r\n" + System.DateTime.Now.ToString() + "\r\n" + s + "\r\n";
byte[] b = System.Text.Encoding.Default.GetBytes(strToWrite);
fs.Write(b, 0, b.Length);
fs.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//获取日志的名称,按天
public static string GetLogfile()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
string date = System.DateTime.Today.ToString("yyyy-MM-dd");
sb.Append(date);
sb.Append(".log");
return sb.ToString();
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。