clr.AddReference("CCPrintingApiNet")
from Chicore import CCPrintingApiNet
from Chicore import ConfigPrintSettings
#獲取所有(yǒu)打印機
getprinters(m_OpenId,m_Tokens,Action[Object](printers_callback))
#打印
printex(m_OpenId,m_Tokens,Action[Object](print_callback))
#獲取打印機回調
def printers_callback(arg):
status = arg.Status
arg0 = arg.Message
sessionid = arg.SessionId
print("Excute Status: {:d}, SessionId:{:s}".format(status, sessionid))
if arg0 == None:
return
#獲取成功,顯示所有(yǒu)打印機
if status == 1 :
for i in range(1,len(arg0)):
print(arg0[i])
#獲取打印機
def getprinters(openid,token,callback):
cfgData = ConfigPrintSettings()
cfgData.XAction = "Printers"
cfgData.XOpenId = openid
cfgData.XTokens = token
CCPrintingApi.ExcuteEx(cfgData,callback)
#打印回調
def print_callback(arg):
status = arg.Status
arg0 = arg.Message
sessionid = arg.SessionId
print("Excute Status: {:d}, SessionId:{:s}".format(status, sessionid))
if arg0 == None:
return
#打印成功
if status == 1 :
print("{:s}:{:s}".format(arg0[0],arg0[1]))
#執行(xíng)打印
def printex(openid,token,callback):
cfgData = ConfigPrintSettings()
cfgData.XAction = "Print"
cfgData.XOpenId = openid
cfgData.XTokens = token
cfgData.PrinterName = "Honeywell PC42t (203 dpi) - DP"
#使用模闆
cfgData.TemplateMode = 1
cfgData.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API"
cfgData.TemplateName ="183601-70X40.Lblx"
#傳入數(shù)據
newprtdata = "987650002;CCPrintingAPI;測試産品 API新接口"
prtdata = "[{sku:'OBJ100001',name:'測試1',kw:'D12-1',bh:'RKD123451'},{sku:'OBJ100002',name:'測試2',kw:'D12-2',bh:'RKD123452'}]"
cfgData.PrintDataType = 1
cfgData.PrintData = prtdata
CCPrintingApi.ExcuteEx(cfgData,callback)