[BD2.0] ThinkPHP中写API接口, 支付回调等

65 阅读1分钟

可能是由于BD封装的原因, 直接请求API会返回一个含有很多js的页面, 并不显示任何内容, 只需要加server=1即可

例如支付回调的接口

http://localhost:8000/api/PayNotify/wechat?server=1

image.png

如果自己创建控制器

php think make:controller Index
http://localhost:8000/index/index?server=1
<?php
declare (strict_types = 1);

namespace app\controller;

use think\Request;

class Index
{
    public function index()
    {
        $data = [
            'message' => '这是一个简单的API示例',
        ];
        return json($data);
    }
}