<?php
namespace Api\Controller;

use Think\Controller;

header("Content-Type:text/html;CharSet=UTF-8");
class TestController extends Controller
{
    public function templateMsg()
    {
        $formId = $_GET['formId'];
        $openid = $_GET['openid'];
        if (!$formId || $formId == "undefined" || $formId == "null") {
            $data = array("status" => -1, "msg" => "formId 有误");
        } elseif (!$openid || $openid == "undefined" || $openid == "null") {
            $data = array("status" => -1, "msg" => "openid 有误");
        } else {
            vendor("WxPayPubHelper.WxPlugin");
            $WxPlugin = new \WxPlugin();
            $params['form_id'] = $formId;
            $params['touser'] = $openid;
            $params['template_id'] = "rN8CLJwHT944lNxOj_DgKuwSIefnDFkUXWamszJWexQ";
            $params['data'] = array(
                "keyword1" => array("value" => date("Y年m月d日", $_SERVER['REQUEST_TIME']), "color" => "#173177"),
                "keyword2" => array("value" => "功能测试", "color" => "#173177")
            );
            $result = $WxPlugin->XcxSend($params);
            if ($result['status'] == 1) {
                $data = array(
                    "status" => 1,
                    "msg" => "发送成功"
                );
            } elseif ($result['status'] == -1) {
                $data = array(
                    "status" => -1,
                    "msg" => $result['msg'],
                    "template" => $result['template']
                );
            }
        }
        apiReturn($data);
    }
}