微擎通过扫码触发指定应用

微擎通过扫码触发指定应用

 

实现流程:

  1. 确认安装配置文件 manifest.xml 中 
    <rule embed="true" /> 配置项是否为true
  2. 关键字,规则是在 ims_rule  、ims_rule_keyword 中,将你想触发的关键字,按数据表的要求插入
# ################################## 生成触发关键字 #################################
$rule = pdo_get('rule', array('uniacid' => $_W['uniacid'], 'module' => 'dev_help'));
if (empty($rule)) {
    // 1、关键字不存在创建关键字
    $rule_data = array('uniacid' => $_W['uniacid'], 'module' => 'dev_help', 'displayorder' => 0, 'status' => 1);
    pdo_insert('rule', $rule_data);
    $rid = pdo_get('rule', array('uniacid' => $_W['uniacid'], 'module' => 'dev_help'), array('id'))['id'];
    $keyword_data = array('uniacid' => $_W['uniacid'], 'rid' => $rid, 'module' => 'dev_help', 'content' => 'dev_help', 'type' => 1, 'displayorder' => 0, 'status' => 1);
    pdo_insert('rule_keyword', $keyword_data);
} elseif ($rule['status'] == 0) {
    // 2、关键字被禁用,启用关键字
    pdo_update('rule', array('status' => 1), array('uniacid' => $_W['uniacid'], 'module' => 'dev_help'));
    pdo_update('rule_keyword', array('status' => 1), array('uniacid' => $_W['uniacid'], 'module' => 'dev_help'));
}
# ################################# END生成触发关键字 ################################

       3. 通过 barCodeCreateFixed 生成永久二维码

# ############################### 生成永久二维码 ###############################
$scene_str = $device->IotId;
$barcode = array(
    'action_name' => 'QR_LIMIT_STR_SCENE',
    'action_info' => array(
        'scene' => array(
            'scene_str' => $scene_str
        ),
    ),
);
$account_api = WeAccount::create();
$result = $account_api->barCodeCreateFixed($barcode);
# ############################## END生成永久二维码 ##############################

       4. 在扫码表中,按规则插入数据即可。

# ################################# qrcode数据插入 ################################
$qrcode_data = array(
    'uniacid' => $_W['uniacid'],
    'acid' => $_W['acid'],
    'type' => 'scene',
    'extra' => 0,
    'qrcid' => 0,
    'scene_str' => $scene_str,
    'name' => 'dev_help',
    'keyword' => 'dev_help',
    'model' => 2,
    'ticket' => $result['ticket'],
    'url' => $result['url'],
    'expire' => 0,
    'subnum' => 0,
    'createtime' => time(),
    'status' => 1,
);
pdo_insert('qrcode', $qrcode_data);
# ################################ ENDqrcode数据插入 ###############################

 

posted @ 2019-10-30 15:50  GetcharZp  阅读(578)  评论(0编辑  收藏  举报