Third.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\api\controller\v2;
  3. use app\api\controller\Api;
  4. use app\common\library\DyGameOpen;
  5. /**
  6. * 第三方对接管理
  7. */
  8. class Third extends Api
  9. {
  10. // 抖音 code 换取 access_token
  11. public function getDyCode(){
  12. $code = $this->input('code');
  13. $game_id = $this->input('gameid');
  14. if(empty($code) || empty($game_id)){
  15. $this->jsonResult('', 0, '非法请求,缺少必要参数!');
  16. }
  17. try{
  18. $dyResult = (new DyGameOpen($game_id, 'game_id'))->getAccessToken($code);
  19. if($dyResult['code'] != 100){
  20. $this->jsonResult([], 0, $dyResult['msg']);
  21. }
  22. }catch (\Exception $e){
  23. $this->jsonResult([], 0, "error: ".$e->getMessage());
  24. }
  25. $this->jsonResult($dyResult['data'], 1, 'success');
  26. }
  27. // 抖音 查询绑定意愿
  28. public function getDyAuthInfoOpen(){
  29. $open_id = $this->input['open_id'];
  30. $game_id = $this->input('gameid');
  31. if(empty($open_id) || empty($game_id)){
  32. $this->jsonResult('', 0, '非法请求,缺少必要参数!');
  33. }
  34. try{
  35. $result = (new DyGameOpen($game_id, 'game_id'))->getAuthInfoOpen($open_id);
  36. if($result['code'] != 100){
  37. $this->jsonResult([], 0, $result['msg']);
  38. }
  39. }catch (\Exception $e){
  40. $this->jsonResult([], 0, "error: ".$e->getMessage());
  41. }
  42. $this->jsonResult($result['data'], 1, 'success');
  43. }
  44. // 抖音 游戏内授权后回调抖音游戏
  45. public function getJumpAuthCallback(){
  46. $is_agree = $this->input['is_agree'];
  47. $scheme = $this->input['scheme'];
  48. $username = $this->input['username'];
  49. $game_id = $this->input('game_id');
  50. if(empty($is_agree) || empty($scheme) || empty($username) || empty($game_id)){
  51. $this->jsonResult([], 0, '非法请求,缺少必要参数!');
  52. }
  53. try{
  54. $result = (new DyGameOpen($game_id, 'game_id'))->getJumpAuthCallback($is_agree, $username, $scheme);
  55. if($result['code'] != 100){
  56. $this->jsonResult([], 0, $result['msg']);
  57. }
  58. }catch (\Exception $e){
  59. $this->jsonResult([], 0, "error: ".$e->getMessage());
  60. }
  61. $this->jsonResult($result['data'], 1, 'success');
  62. }
  63. }