diff --git a/app/admin/controller/MiniProgramController.php b/app/admin/controller/MiniProgramController.php index b2a1dd9..1228fdb 100644 --- a/app/admin/controller/MiniProgramController.php +++ b/app/admin/controller/MiniProgramController.php @@ -111,4 +111,34 @@ class MiniProgramController extends BaseController return success($data); } + public function getTests(Request $request) + { + $id = $request->post('id'); + $row = Authorizers::where('id', $id)->find(); + $miniprogram = new MiniProgram($row['platform_id']); + $result = $miniprogram->getTester($row['appid']); + return json(['code' => $result['errcode'], 'msg' => $result['errmsg'], 'data' => $result['members']]); + } + + public function bindTester(Request $request) + { + $id = $request->post('id'); + $wechatId = $request->post('wechat_id'); + $remark = $request->post('remark'); + $row = Authorizers::where('id', $id)->find(); + $miniprogram = new MiniProgram($row['platform_id']); + $result = $miniprogram->bindTester($row['appid'], $wechatId,$remark); + return json(['code' => $result['errcode'], 'msg' => $result['errmsg']]); + } + + public function unbindTester(Request $request) + { + $id = $request->post('id'); + $userstr = $request->post('userstr'); + $row = Authorizers::where('id', $id)->find(); + $miniprogram = new MiniProgram($row['platform_id']); + $result = $miniprogram->unbindTester($row['appid'], $userstr); + return json(['code' => $result['errcode'], 'msg' => $result['errmsg']]); + } + } \ No newline at end of file diff --git a/app/admin/model/Tester.php b/app/admin/model/Tester.php new file mode 100644 index 0000000..29af36e --- /dev/null +++ b/app/admin/model/Tester.php @@ -0,0 +1,25 @@ +order('id', 'desc') + ->paginate([ + 'page' => $params['current_page'], + 'list_rows' => $params['page_size'] + ])->toArray(); + } +} \ No newline at end of file diff --git a/app/common/model/Tester.php b/app/common/model/Tester.php new file mode 100644 index 0000000..bc2c7e8 --- /dev/null +++ b/app/common/model/Tester.php @@ -0,0 +1,14 @@ + 'authorizer_appid', 'name' => 'authorizer_appid'], + ]; + protected $table = 'tester'; +} \ No newline at end of file diff --git a/app/common/service/wechat/MiniProgram.php b/app/common/service/wechat/MiniProgram.php index 3e94f45..f249763 100644 --- a/app/common/service/wechat/MiniProgram.php +++ b/app/common/service/wechat/MiniProgram.php @@ -10,6 +10,7 @@ use EasyWeChat\Kernel\Support\Collection; use GuzzleHttp\Exception\GuzzleException; use Psr\Http\Message\ResponseInterface; use Tinywan\ExceptionHandler\Exception\BadRequestHttpException; +use app\admin\model\Tester; class MiniProgram extends OpenPlatform { @@ -164,4 +165,56 @@ class MiniProgram extends OpenPlatform $params['action'] = 'set'; return $this->getMiniProgram($appid)->domain->modify($params); } + + public function getTester($appid) + { + $result = $this->getMiniProgram($appid)->tester->list(); + if ($result['errcode'] == 0) { + $dbTester = Tester::where('authorizer_appid', $appid)->select()->toArray(); + $txTesterUserstrs = array_column($result['members'], 'userstr'); + $dbTesterUserstrs = array_column($dbTester, 'userstr'); + // 小程序后台有添加体验者,系统中未记录,需要wechat-mp系统中也自动添加 + $notInTxArray = array_diff($txTesterUserstrs, $dbTesterUserstrs); + $insertData = []; + foreach ($notInTxArray as $userstr) { + $data = [ + 'authorizer_appid' => $appid, + 'userstr' => $userstr, + 'remark' => '未知', + 'wechat_id' => '未知', + ]; + array_push($insertData, $data); + } + if (!empty($insertData)) { + Tester::insertAll($insertData,false); + } + + // wechat-mp系统有添加体验者,小程序后台中未记录(可能在平台或其他位置被删了),需要系统中自动删掉 + $notInDbArray = array_diff($dbTesterUserstrs, $txTesterUserstrs); + Tester::where('authorizer_appid', $appid)->whereIn('userstr', $notInDbArray)->delete(); + $dbTester = Tester::list(['authorizer_appid' => $appid]); + return ['errcode' => 0, 'errmsg' => '', 'members' => $dbTester]; + } + return $result; + } + + public function bindTester($appid, $wechatId, $remark) + { + $result = $this->getMiniProgram($appid)->tester->bind($wechatId); + if ($result['errcode'] == 0) { + $data = [ + 'authorizer_appid' => $appid, + 'wechat_id' => $wechatId, + 'remark' => $remark, + 'userstr' => $result['userstr'] + ]; + Tester::create($data); + } + return $result; + } + + public function unbindTester($appid, $userStr) + { + return $this->getMiniProgram($appid)->tester->unbind(null,$userStr); + } } \ No newline at end of file diff --git a/front/src/api/miniprogram.js b/front/src/api/miniprogram.js index 080302f..20563d0 100644 --- a/front/src/api/miniprogram.js +++ b/front/src/api/miniprogram.js @@ -11,6 +11,9 @@ const api = { RevertCodeRelease: '/miniprogram/revertCodeRelease', SetDomain: '/miniprogram/setDomain', getPcAuthorizerUrl: '/miniprogram/getPcAuthorizerUrl', + getTests: '/miniprogram/getTests', + bindTester: '/miniprogram/bindTester', + unbindTester: '/miniprogram/unbindTester', } export function getDetail(parameter) { @@ -92,3 +95,27 @@ export function getPcAuthorizerUrl(parameter) { data: parameter }) } + +export function getTests(parameter) { + return request({ + url: api.getTests, + method: 'post', + data: parameter + }) +} + +export function bindTester(parameter) { + return request({ + url: api.bindTester, + method: 'post', + data: parameter + }) +} + +export function unbindTester(parameter) { + return request({ + url: api.unbindTester, + method: 'post', + data: parameter + }) +} \ No newline at end of file diff --git a/front/src/views/authorizer/detail.vue b/front/src/views/authorizer/detail.vue index ef2b2d9..1fd5462 100644 --- a/front/src/views/authorizer/detail.vue +++ b/front/src/views/authorizer/detail.vue @@ -8,6 +8,9 @@ + + + @@ -16,12 +19,14 @@ + + \ No newline at end of file diff --git a/install.sql b/install.sql index 284f164..5a6131b 100644 --- a/install.sql +++ b/install.sql @@ -111,5 +111,19 @@ CREATE TABLE `wxcallback_forward` ) ENGINE = InnoDB DEFAULT CHARSET = utf8 COMMENT ='请求转发日志'; +-- 体验者列表 +CREATE TABLE `tester` +( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `authorizer_appid` varchar(32) NOT NULL COMMENT '授权小程序的appid', + `wechat_id` varchar(255) NOT NULL COMMENT '微信号', + `userstr` varchar(255) NOT NULL COMMENT 'userstr', + `remark` varchar(255) DEFAULT NULL COMMENT '备注', + `create_time` int(11) NOT NULL, + `update_time` int(11) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB + DEFAULT CHARSET = utf8 COMMENT ='体验者列表'; + INSERT INTO `user` (`id`, `username`, `password`, `create_time`, `update_time`) VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 1717411365, 1717411365);