设置所属行业

$obj = new \wechat\Wechat();
// false.失败 true.成功
$obj->official()->template()->set_industry([
    "industry_id1" => "2",
    "industry_id2" => "1"
]);

获取设置的行业信息

$obj = new \wechat\Wechat();
$obj->official()->template()->get_industry([
    "industry_id1" => "2",
    "industry_id2" => "1"
]);

成功结果:

array(2) {
  ["primary_industry"] => array(2) {
    ["first_class"] => string(8) "IT科技"
    ["second_class"] => string(17) "IT软件与服务"
  }
  ["secondary_industry"] => array(2) {
    ["first_class"] => string(8) "IT科技"
    ["second_class"] => string(22) "互联网|电子商务"
  }
}

获取模板ID

$obj = new \wechat\Wechat();
$obj->official()->template()->get_id([
    "template_id_short" => "TM00303"
]);

成功结果:

string(43) "PU1xmh6wXnKAwM3G5KM43HtZUZ6eRqr-onOMOYUGB5c"

获取模板列表

$obj = new \wechat\Wechat();
$obj->official()->template()->get_list();

成功结果:

array(2) {
  [0] => array(6) {
    ["template_id"] => string(43) "VwsO7WOXJaGlu8Okwcy_V2gY6Rv1V1eEs1QtoGjTOsM"
    ["title"] => string(21) "商品已发出通知"
    ["primary_industry"] => string(8) "IT科技"
    ["deputy_industry"] => string(22) "互联网|电子商务"
    ["content"] => string(105) "内容太多,删掉了"
    ["example"] => string(214) ""
  }
  [1] => array(6) {
    ["template_id"] => string(43) "PU1xmh6wXnKAwM3G5KM43HtZUZ6eRqr-onOMOYUGB5c"
    ["title"] => string(21) "商品已发出通知"
    ["primary_industry"] => string(8) "IT科技"
    ["deputy_industry"] => string(22) "互联网|电子商务"
    ["content"] => string(105) "内容太多,删掉了"
  }
}

删除模板

$obj = new \wechat\Wechat();
// false.失败 true.成功
$obj->official()->template()->delete_industry([
    'template_id' => 'PU1xmh6wXnKAwM3G5KM43HtZUZ6eRqr-onOMOYUGB5c'
])

发送消息模板

$obj = new \wechat\Wechat();
// false.失败 true.成功
$obj->official()->template()->send([
    "touser" => "oyYsU6tp45nGmTZlRuzeX6lksxMI",
    "template_id" => "VwsO7WOXJaGlu8Okwcy_V2gY6Rv1V1eEs1QtoGjTOsM",
    "url" => "http://weixin.qq.com/download",        
    "data" => [
        "first" => [
            "value" => "恭喜你购买成功!",
            "color" => "#173177"
        ],
        "delivername" => [
            "value" => "巧克力",
            "color" => "#173177"
        ],
        "ordername" => [
            "value" => "39.8元",
            "color" => "#173177"
        ],
        "remark" => [
            "value" => "欢迎再次购买!",
            "color" => "#173177"
        ]
    ]
])

生成一次性订阅授权链接

$obj = new \wechat\Wechat();
$obj->official()->template()->disposable_auth_url([
    "scene" => mt_rand(1, 10000),
    "template_id" => 'VwsO7WOXJaGlu8Okwcy_V2gY6Rv1V1eEs1QtoGjTOsM',
    "redirect_url" => 'https://www.sw-x.cn',
    "reserved" => 'test',
]);

成功结果:

https://mp.weixin.qq.com/mp/subscribemsg?action=get_confirm&appid=wxa7e83f7920622541&scene=4334&template_id=VwsO7WOXJaGlu8Okwcy_V2gY6Rv1V1eEs1QtoGjTOsM&redirect_url=https%3A%2F%2Fwww.sw-x.cn&reserved=test#wechat_redirect

发送一次性订阅消息模板

$obj = new \wechat\Wechat();
// false.失败 true.成功
$obj->official()->template()->disposable_auth_send('{
    "touser": "oyYsU6tp45nGmTZlRuzeX6lksxMI",
    "template_id": "VwsO7WOXJaGlu8Okwcy_V2gY6Rv1V1eEs1QtoGjTOsM",
    "url": "URL",
    "miniprogram": {
      "appid": "xiaochengxuappid12345",
      "pagepath": "index?foo=bar"
    },
    "scene": "SCENE",
    "title": "TITLE",
    "data": {
      "content": {
        "value": "VALUE",
        "color": "COLOR"
      }
    }
}');

SW-X

企业级 - 高性能 PHP 框架

最后更新:3年前 . 作者-小黄牛

本篇目录