1、登录打印控制
2、打印界面

主要代码:
定期刷新token
public void fresh_token(string refresh_token, string storename, string userid)
{
string appkey = " ";
string apSecret = " ";
string method = "token.refresh";
string shopid = " ";
// string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
string v = "2";
string sign = "";
string param_json = "";
//string param_json = "{\"code\":\"" + code + "\",\"grant_type\":\"authorization_self\",\"shop_id\":\"" + shopid + "\"}";
//sign = Sign(apkey, appSecret, method, timestamp, param_json);
var host = "https://openapi-fxg.jinritemai.com";
var m = new Dictionary<string, object>
{
// {"authorization_self", "authorization_self"},
{"refresh_token", refresh_token},//附加符号、中日韩、Emoji都不转义
{"grant_type", "refresh_token"},
// {"shop_id", "47882"},
};
// 序列化参数
var paramJson = Marshal(m);
Console.WriteLine("param_json:" + paramJson);
// 计算签名
var signVal = Sign(ap_key, appSecret, method, timestamp, paramJson);
Console.WriteLine("sign_val:" + signVal);
var accessToken = "";
// 发起请求
var responseVal = Fetch(app_key, host, method, timestamp, paramJson, accessToken, signVal);
Console.WriteLine("response_val:" + responseVal);
try
{
token root = JsonConvert.DeserializeObject<token>(responseVal);
// MessageBox.Show("成功:" + root.data.access_token + ":" + root.data.refresh_token);
// t_access.Text = root.data.access_token;
// t_token.Text = root.data.refresh_token;
boxdata.Updata_StoreName(storename, root.data.access_token, root.data.refresh_token, root.data.shop_name, userid);
}
catch (Exception ex)
{
MessageBox.Show(storename +":"+ responseVal + ":" + ex.Message);
}
}
打印方法
private string print(string token,string cysname, string boxno, string encryptedData,string signature,string temp, string key1, string key2, string key3)
{
string templateURL = "";
string printer = pdd_prn_sf;
if (cysname == "北京圆通(抖音)" || cysname == "北京圆通速递" || cysname == "北京圆通(抖音)")
{
printer = pdd_prn_yt;
templateURL="https://pos-file.pinduoduo.com/express-common-no-cache/common/xmltemplate/printtemplate_bcf2e7d099d742fab6ee06af728cc92a.xml";
templateURL = pdd_tmp_yt;
temp= pdd_temp_yt;
}
if (cysname == "北京顺丰(电商)" || cysname == "北京顺丰" || cysname == "北京顺丰(抖音)")
{
printer = pdd_prn_sf;
// templateURL = "https://pos-file.pinduoduo.com/express-common-no-cache/common/xmltemplate/printtemplate_4c4ab5136fa44c0b8d395b2112465eac.xml";
templateURL = pdd_tmp_sf;
temp = pdd_temp_sf;
}
if (cysname == "北京顺丰(抖音)" || cysname == "北京顺丰" || cysname == "北京顺丰(抖音)")
{
printer = pdd_prn_sf;
// templateURL = "https://pos-file.pinduoduo.com/express-common-no-cache/common/xmltemplate/printtemplate_4c4ab5136fa44c0b8d395b2112465eac.xml";
templateURL = pdd_tmp_sf;
temp = pdd_temp_sf;
}
if (cysname == "北京中通(抖音)" || cysname == "北京中通" || cysname == "北京中通(抖音)")
{
printer = pdd_prn_zt;
templateURL = pdd_tmp_zt;
temp = pdd_temp_zt;
}
if (cysname == "北京EMS" || cysname == "北京EMS" )
{
printer = pdd_prn_ems;
templateURL = pdd_tmp_ems;
temp = pdd_temp_ems;
}
if (cysname == "北京京东物流" || cysname == "北京京东物流")
{
printer = pdd_prn_jd;
templateURL = pdd_tmp_jd;
temp = pdd_temp_jd;
}
if (templateURL=="")
{
return "-1";
}
string appkey = " ";
string appSecret = " ";
string method = "logistics.getShopKey";
string sign = "";
long timestamp = DateTimeOffset.Now.ToUnixTimeSeconds();
string v = "2";
var m = new Dictionary<string, object>
{
// {"shop_id", " "},
};
var paramJson = Marshal(m);
Console.WriteLine("param_json:" + paramJson);
// 计算签名
var signVal = Sign(appkey, appSecret, method, timestamp, paramJson);
sign = signVal;
string access_token = token;
String input1 = "{\"cmd\":\"print\"," +
"\"requestID\":\""+boxno+"\"," +
"\"version\":\"1.0\"," +
"\"task\":" +
"{\"taskID\":\"" + boxno + "\"," +
"\"preview\":false," +
"\"previewType\":\"image\"," +
"\"printer\":\"" + printer + "\"," +
"\"notifyMode\":\"allInOne\"," +
"\"firstDocumentNumber\":1," +
"\"totalDocumentCount\":1," +
"\"documents\":" +
"[{\"documentID\":\""+boxno+"\"," +
"\"contents\":" +
"[{\"encryptedData\":\"" + encryptedData + "\"," +
"\"signature\":\""+signature +"\","+
"\"params\":\"access_token=" + access_token + "&app_key=" + appkey + "&method=" + method + "¶m_json=" + paramJson + "×tamp=" + timestamp + "&v=" + v + "&sign=" + sign + "&sign_method=" + "hmac-sha256" + "\"," +
"\"templateURL\":\"" + temp + "\"}," +
"{\"templateURL\":\"" + templateURL + "\"," +
" \"data\":{" +
"\"KEY1\":\""+key1+"\","+
"\"KEY2\":\"" + key2 + "\"," +
"\"KEY3\":\"" + key3 + "\"}}" +
"]}]}}";
try
{
websocket.Send(input1);
return "0";
}catch (Exception ex)
{
return "-2";
}
}
1128

被折叠的 条评论
为什么被折叠?



