Gaoming13\WechatPhpSdk\Api::create_kf_session PHP Method

create_kf_session() public method

创建客户与客服的会话
public create_kf_session ( string $openid, string $kf_account, string $text = '' ) : array(err,
$openid string
$kf_account string
$text string (可选)
return array(err,
    public function create_kf_session($openid, $kf_account, $text = '')
    {
        $url = self::API_DOMAIN . 'customservice/kfsession/create?access_token=' . $this->get_access_token();
        $xml = sprintf('{
                    "kf_account" : "%s",
                    "openid" : "%s",
                    "text" : "%s"}', $kf_account, $openid, $text);
        $res = HttpCurl::post($url, $xml, 'json');
        // 异常处理: 获取时网络错误
        if ($res === false) {
            return Error::code('ERR_GET');
        }
        // 判断是否调用成功
        if ($res->errcode == 0) {
            return array(null, true);
        } else {
            return array($res, null);
        }
    }