开放平台

介绍

# 打印机

# wmpf.printer

传递文本内容到设备打印机服务 - 异步返回

# 示例代码

wmpf.printer({
  data: [ // data 中的所有信息将会透传至业务方,对应到 Intent Extra Data 中的 raw_data 数据	
    {
      "type": "base_string",
      "content": "XXXX信息技术有限公司",
      "style": {
        "fontSize": 30,
        "bold": 1
      }

    },
    {
      "type": "base_string",
      "content": "顾客信息",
      "style": {
        "fontSize": 25,
        "bold": 1
      }

    },
    {
      "type": "both_side",
      "content": {
        "left": "顾客姓名",
        "right": "Kommi"
      },
      "style": {
        "fontSize": 20,
        "bold": 0
      }

    },
    {
      "type": "base_string",
      "content": "其他信息",
      "style": {
        "fontSize": 25,
        "bold": 1
      }

    },
    {
      "type": "both_side",
      "content": {
        "left": "核销门店",
        "right": "为你客407国道店"
      },
      "style": {
        "fontSize": 20,
        "bold": 0
      }

    },
    {
      "type": "both_side",
      "content": {
        "left": "核销码",
        "right": "5665470281092409"
      },
      "style": {
        "fontSize": 20,
        "bold": 0
      }

    },
    {
      "type": "barcode",
      "content": "5665470281092409",
      "barCodeOption": {
        "barWidth": "normal",
      }

    }

  ],
  success: (res) => {
    console.log(res)
  },
  fail: (res) => {
    console.log(res)
  }
})

# WMPF Client 侧数据处理

WMPF 框架接到开发者在前端发出的 print 请求后,将以 startAcitivtyForResult 的调用方式通知到 WMPF Client侧,因此 WMPF Client 侧需要注册一个 Action 为 com.tencent.wmpf.action.WMPF_PRINTER 的 Activity 以接收来自 WMPF 框架的透传调用数据。

调用数据存于 Intent 中,可在 Activity 中通过 getIntent() 的方式获取。Intent 中包含的数据说明如下:

参数 类型 说明
raw_data string 透传的原始打印数据,对应到前端调用为 data 字段中的数据
key_time_stamp int 调用时间戳
key_token string 调用验证,格式为 MD5 ( appid + "_" + key_time_stamp )
# 回调

WMPF Client 侧处理完打印请求后,需要回调至WMPF框架侧通知整个调用流程已结束,以提供正确的前端回调。回调参数同样包含在 Intent 中,通过 setResult(resultCode,intent) 方式传递,resultCode 根据实际调用结果取值, Intent 中包含的回调数据说明如下:

参数 类型 说明
result_code int 打印结果反馈值,由开发者自定义,值将透传至前端