飞鹅云打印 API_C#
作者:互联网
飞鹅云打印: 提交订单支付成功后台自动打印,实现无人销售,自动打印,后台统计打印记录功能;
有自带WIFY:连接到wify就可以打印小票;
有自动SIM卡:第1年免流量费,第2年30一年
#region 飞鹅云打印-API
//飞鹅云打印
public string print(string USER, string UKEY, string SN, string merchantName, string payType, string payTotalMoney, string realyPayTotalMoney, string payStatus, string orderNo, string deviceNo, string qrurl)
{
//标签说明:
//单标签:
//"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
//"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
//成对标签:
//"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
//<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐 //string USER = //*必填*:登录管理后台的账号名
//string UKEY =//*必填*: 注册账号后生成的UKEY
//string SN = //*必填*:打印机编号,必须要在管理后台里手动添加打印机或者通过API添加之后,才能调用API string URL = "http://api.feieyun.cn/Api/Open/";//不需要修改 //拼凑订单内容时可参考如下格式
string orderInfo;
//orderInfo = "<CB>中国福彩惠州</CB><BR>";
//orderInfo += "<BR>";
//orderInfo += "--------------------------------<BR>";
//orderInfo += "交易类型:" + " 微信支付<BR>";
//orderInfo += "总金额:" + " 100.00元<BR>";
//orderInfo += "用户实付:" + " 100.00元<BR>";
//orderInfo += "支付状态:" + " 支付完成<BR>";
//orderInfo += "--------------------------------<BR>";
//orderInfo += "订单编号:" + "<BR>";
//orderInfo += "终端编号:" + SN + "<BR>";
//orderInfo += "台号:" + " *** <BR>";
//orderInfo += "日期:" + System.DateTime.Now + " <BR>";
//orderInfo += "----------请扫描二维码----------";
//orderInfo += "<QR>http://www.dzist.com</QR>";//把二维码字符串用标签套上即可自动生成二维码
//orderInfo += "<BR>"; orderInfo = "<CB>" + merchantName + "</CB><BR>";
orderInfo += "<BR>";
orderInfo += "--------------------------------<BR>";
orderInfo += "交易类型:" + payType + "<BR>";
orderInfo += "总金额:" + payTotalMoney + "元<BR>";
orderInfo += "用户实付:" + realyPayTotalMoney + "元<BR>";
orderInfo += "支付状态:" + payStatus + "<BR>";
orderInfo += "--------------------------------<BR>";
orderInfo += "订单编号:" + orderNo + "<BR>";
orderInfo += "终端编号:" + SN + "<BR>";
orderInfo += "台号:" + deviceNo + "<BR>";
orderInfo += "日期:" + System.DateTime.Now + " <BR>";
//orderInfo += "----------请扫描二维码----------";
orderInfo += "--------------------------------";
orderInfo += "请妥善保管好购物凭证 多谢惠顾!";
orderInfo += "<QR>" + qrurl + "</QR>";//把二维码字符串用标签套上即可自动生成二维码
orderInfo += "<BR>"; orderInfo = Uri.EscapeDataString(orderInfo);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
req.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding(); string postData = "sn=" + SN;
postData += ("&content=" + orderInfo);
postData += ("×=" + "1");//默认1联 int itime = DateTimeToStamp(System.DateTime.Now);//时间戳秒数
string stime = itime.ToString();
string sig = sha1(USER, UKEY, stime); //公共参数
postData += ("&user=" + USER);
postData += ("&stime=" + stime);
postData += ("&sig=" + sig);
postData += ("&apiname=" + "Open_printMsg"); byte[] data = encoding.GetBytes(postData); req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream resStream = req.GetRequestStream(); resStream.Write(data, 0, data.Length);
resStream.Close(); HttpWebResponse response;
string strResult;
try
{
response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
strResult = reader.ReadToEnd();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
strResult = response.StatusCode.ToString();//错误信息
} response.Close();
req.Abort();
//服务器返回的JSON字符串,建议要当做日志记录起来
Logger.Instance.APIInfoFormat("飞鹅云打印 result->{0}", strResult);
return strResult; } //签名USER,UKEY,STIME
public static string sha1(string user, string ukey, string stime)
{
var buffer = Encoding.UTF8.GetBytes(user + ukey + stime);
var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder();
foreach (var t in data)
{
sb.Append(t.ToString("X2"));
} return sb.ToString().ToLower(); } private static int DateTimeToStamp(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds;
} #endregion
public string print(string USER, string UKEY, string SN, string merchantName, string payType, string payTotalMoney, string realyPayTotalMoney, string payStatus, string orderNo, string deviceNo, string qrurl)
{
//标签说明:
//单标签:
//"<BR>"为换行,"<CUT>"为切刀指令(主动切纸,仅限切刀打印机使用才有效果)
//"<LOGO>"为打印LOGO指令(前提是预先在机器内置LOGO图片),"<PLUGIN>"为钱箱或者外置音响指令
//成对标签:
//"<CB></CB>"为居中放大一倍,"<B></B>"为放大一倍,"<C></C>"为居中,<L></L>字体变高一倍
//<W></W>字体变宽一倍,"<QR></QR>"为二维码,"<BOLD></BOLD>"为字体加粗,"<RIGHT></RIGHT>"为右对齐 //string USER = //*必填*:登录管理后台的账号名
//string UKEY =//*必填*: 注册账号后生成的UKEY
//string SN = //*必填*:打印机编号,必须要在管理后台里手动添加打印机或者通过API添加之后,才能调用API string URL = "http://api.feieyun.cn/Api/Open/";//不需要修改 //拼凑订单内容时可参考如下格式
string orderInfo;
//orderInfo = "<CB>中国福彩惠州</CB><BR>";
//orderInfo += "<BR>";
//orderInfo += "--------------------------------<BR>";
//orderInfo += "交易类型:" + " 微信支付<BR>";
//orderInfo += "总金额:" + " 100.00元<BR>";
//orderInfo += "用户实付:" + " 100.00元<BR>";
//orderInfo += "支付状态:" + " 支付完成<BR>";
//orderInfo += "--------------------------------<BR>";
//orderInfo += "订单编号:" + "<BR>";
//orderInfo += "终端编号:" + SN + "<BR>";
//orderInfo += "台号:" + " *** <BR>";
//orderInfo += "日期:" + System.DateTime.Now + " <BR>";
//orderInfo += "----------请扫描二维码----------";
//orderInfo += "<QR>http://www.dzist.com</QR>";//把二维码字符串用标签套上即可自动生成二维码
//orderInfo += "<BR>"; orderInfo = "<CB>" + merchantName + "</CB><BR>";
orderInfo += "<BR>";
orderInfo += "--------------------------------<BR>";
orderInfo += "交易类型:" + payType + "<BR>";
orderInfo += "总金额:" + payTotalMoney + "元<BR>";
orderInfo += "用户实付:" + realyPayTotalMoney + "元<BR>";
orderInfo += "支付状态:" + payStatus + "<BR>";
orderInfo += "--------------------------------<BR>";
orderInfo += "订单编号:" + orderNo + "<BR>";
orderInfo += "终端编号:" + SN + "<BR>";
orderInfo += "台号:" + deviceNo + "<BR>";
orderInfo += "日期:" + System.DateTime.Now + " <BR>";
//orderInfo += "----------请扫描二维码----------";
orderInfo += "--------------------------------";
orderInfo += "请妥善保管好购物凭证 多谢惠顾!";
orderInfo += "<QR>" + qrurl + "</QR>";//把二维码字符串用标签套上即可自动生成二维码
orderInfo += "<BR>"; orderInfo = Uri.EscapeDataString(orderInfo);
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(URL);
req.Method = "POST";
UTF8Encoding encoding = new UTF8Encoding(); string postData = "sn=" + SN;
postData += ("&content=" + orderInfo);
postData += ("×=" + "1");//默认1联 int itime = DateTimeToStamp(System.DateTime.Now);//时间戳秒数
string stime = itime.ToString();
string sig = sha1(USER, UKEY, stime); //公共参数
postData += ("&user=" + USER);
postData += ("&stime=" + stime);
postData += ("&sig=" + sig);
postData += ("&apiname=" + "Open_printMsg"); byte[] data = encoding.GetBytes(postData); req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream resStream = req.GetRequestStream(); resStream.Write(data, 0, data.Length);
resStream.Close(); HttpWebResponse response;
string strResult;
try
{
response = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
strResult = reader.ReadToEnd();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;
strResult = response.StatusCode.ToString();//错误信息
} response.Close();
req.Abort();
//服务器返回的JSON字符串,建议要当做日志记录起来
Logger.Instance.APIInfoFormat("飞鹅云打印 result->{0}", strResult);
return strResult; } //签名USER,UKEY,STIME
public static string sha1(string user, string ukey, string stime)
{
var buffer = Encoding.UTF8.GetBytes(user + ukey + stime);
var data = SHA1.Create().ComputeHash(buffer); var sb = new StringBuilder();
foreach (var t in data)
{
sb.Append(t.ToString("X2"));
} return sb.ToString().ToLower(); } private static int DateTimeToStamp(System.DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds;
} #endregion
标签:打印,orderInfo,postData,C#,req,飞鹅云,二维码,API,string 来源: https://www.cnblogs.com/csj007523/p/10421075.html