CoinAirwallex.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. /**
  3. * 官网的公共控制器类
  4. *
  5. */
  6. namespace app\home\controller;
  7. use app\common\logic\PayCallback;
  8. use app\common\model\GameServer;
  9. use app\common\model\MemberCoinPay;
  10. use app\common\model\MemberGameServer;
  11. use app\common\model\Members;
  12. use app\common\model\PayType;
  13. use app\common\model\Subaccount;
  14. use app\service\GamePayService;
  15. use app\service\MemberCoinService;
  16. use app\common\model\Game;
  17. use app\common\logic\Pay as PayLogic;
  18. use think\Cache;
  19. use think\Env;
  20. use think\Exception;
  21. use app\common\library\AirwallexPay;
  22. class CoinAirwallex extends Home
  23. {
  24. //v1.game_pay_type
  25. /**
  26. * 获取支付方式
  27. */
  28. public function getPayType()
  29. {
  30. $denyPayType = [
  31. 'airwallex',
  32. ];
  33. //wx-wap
  34. //xzzfbzf 新支付宝
  35. //old-zfb-wap 旧支付宝
  36. $payTypeModel = new PayType();
  37. $arrPayType = $payTypeModel->field('paytype,payname')
  38. ->where(['paytype' => ['in', $denyPayType]])
  39. ->select();
  40. $this->result($arrPayType, 1, '成功', 'json');
  41. }
  42. //v1.pay
  43. public function pay()
  44. {
  45. $data['type'] = input('type'); //类型 1充值平台币 2 充值游戏
  46. $data['paytype'] = input('paytype'); //支付类型
  47. $data['amount'] = input('amount'); //支付金额
  48. $data['accountType'] = input('accountType'); //账号类型1当前账号2其他账号
  49. $data['username'] = input('username');
  50. $data['gameid'] = input('gameid');
  51. $data['serverid'] = input('serverid');
  52. $data['roleid'] = input('roleid');
  53. $data['ip'] = request()->ip();
  54. $checkResult = $this->validate($data,
  55. [
  56. ['type', 'require|integer|in:1', '类型不能为空|必须为整型'],
  57. ['paytype', 'require', '支付类型不能为空'],
  58. ['amount', 'require|integer|egt:0', '支付金额不能为空|支付金额必须为整型|支付金额大于等于0的整型'],
  59. ['accountType', 'require|in:1,2', '账号类型不能为空|账号类型错误'],
  60. ['username', 'requireIf:accountType,2', '账号必填'],
  61. ['gameid', 'requireIf:type,2|integer', '游戏必填|游戏必须为整型'],
  62. ['serverid', 'requireIf:type,2', '区服必填'],
  63. ['roleid', 'requireIf:type,2', '角色必填'],
  64. ['coin_amt', 'float|egt:0', '金额必须为数字|支付金额大于等于0'],
  65. ]);
  66. if (true !== $checkResult) {
  67. $this->result('', 0, $checkResult, 'json');
  68. }
  69. if (!in_array($data['paytype'], ['airwallex'])) {
  70. $this->jsonResult('', 0, '支付类型错误');
  71. }
  72. if (in_array($data['paytype'], ['airwallex']) && $data['accountType'] != 1) {
  73. $this->jsonResult('', 0, '支付方式错误');
  74. }
  75. if ($data['accountType'] == 2) {
  76. if (!$user = (new Members())->getUseridByName($data)) {
  77. $this->result([], 0, '账号不存在');
  78. }
  79. $data['member_id'] = $user['id'];
  80. } else {
  81. if(!session('front_userid')){
  82. $this->result([], 0, '未登录请先登录');
  83. }
  84. $data['member_id'] = session('front_userid');
  85. if (!$user = (new Members())->getUseridById($data)) {
  86. $this->result([], 0, '账号不存在');
  87. }
  88. }
  89. $data['place_user_id'] = session('front_userid');
  90. if ($data['type'] == 1) {//充值平台币
  91. $data['coin_amt'] = 0;
  92. $result = (new MemberCoinService())->payCoin($data);
  93. }
  94. // else {
  95. //
  96. // $data['attach'] = makeOrderid('CP'); //上一级的扩展参数,多数是订单编号[祈盟文化自己聚合自己时,会加个aoyou###前缀]
  97. // $data['ptb_amt'] = 0; //专属币使用金额
  98. // $data['imeil'] = 'pc'; //手机imeil码
  99. // $data['productname'] = '游戏充值'; //消费的商品名称
  100. //
  101. //
  102. // if($data['accountType'] == 2 || $data['type'] == 1){
  103. // $data['coin_amt'] = 0;
  104. // }else{
  105. // $data['coin_amt'] = input('coin_amt'); //平台币使用金额
  106. // }
  107. //
  108. // $result = (new GamePayService())->gamePay($data,2);
  109. //
  110. // //全部平台币支付,并且支付成功时
  111. // if ($result['code'] == 1 && (isset($result['data']['pay_status'])&& $result['data']['pay_status'] == 1)) {
  112. //
  113. // // 通知CP,支付成功
  114. // (new PayCallback())->callBackToCp($result['data']['orderid']);
  115. // (new PayLogic())->payWarning($data['member_id'], $result['data']['channel_id'], $data['gameid'], $data['amount']);
  116. // }
  117. // }
  118. if ($result['code'] == 1) {
  119. $this->jsonResult($result['data'], 1, (isset($result['data']['pay_status'])&&$result['data']['pay_status'] == 1) ? '付款成功' : '订单生成成功', false);
  120. } else {
  121. $this->jsonResult('', 0, $result['msg']);
  122. }
  123. }
  124. /**
  125. * 获取可支付游戏
  126. */
  127. public function getGameList()
  128. {
  129. $this->result((new Game())->getGameListPay(), 1, '成功');
  130. }
  131. public function getServerList()
  132. {
  133. $data['gameid'] = input('gameid'); //游戏id
  134. $checkResult = $this->validate($data,
  135. [
  136. ['gameid', 'require|integer|gt:0', '游戏id不能为空|游戏id必须为整型|游戏id大于0的整型'],
  137. ]);
  138. if (true !== $checkResult) {
  139. $this->result('', 0, $checkResult, 'json');
  140. }
  141. $this->result((new GameServer())->getServerList($data), 1, '成功');
  142. }
  143. public function getRoleList()
  144. {
  145. $data['gameid'] = input('gameid'); //游戏id
  146. $data['serverid'] = input('serverid'); //游戏id
  147. $data['accountType'] = input('accountType'); //账号类型1当前账号2其他账号
  148. $data['username'] = input('username');
  149. $checkResult = $this->validate($data,
  150. [
  151. ['gameid', 'require|integer|gt:0', '游戏id不能为空|游戏id必须为整型|游戏id大于0的整型'],
  152. ['serverid', 'require|integer|gt:0', '区服id不能为空|区服id必须为整型区服id大于0的整型'],
  153. ['accountType', 'require|in:1,2', '账号类型不能为空|账号类型错误'],
  154. ['username', 'requireIf:accountType,2', '账号必填']
  155. ]);
  156. if (true !== $checkResult) {
  157. $this->result('', 0, $checkResult, 'json');
  158. }
  159. if ($data['accountType'] == 2) {
  160. if (!$user = (new Members())->getUseridByName($data)) {
  161. $this->result([], 0, '账号不存在');
  162. }
  163. $data['userid'] = $user['id'];
  164. } else {
  165. $data['userid'] = session('front_userid');
  166. }
  167. $this->result((new MemberGameServer())->getRoleList($data), 1, '成功');
  168. }
  169. public function verifyUserName()
  170. {
  171. $data['username'] = input('username'); //游戏id
  172. $checkResult = $this->validate($data,
  173. [
  174. ['username', 'require', '账号不能为空'],
  175. ]);
  176. if (true !== $checkResult) {
  177. $this->result('', 0, $checkResult, 'json');
  178. }
  179. $user = (new Members())->getUserName($data);
  180. if ($user) {
  181. $this->result($user, 1, '成功');
  182. } else {
  183. $this->result([], 0, '账号不存在');
  184. }
  185. }
  186. public function payHtml()
  187. {
  188. $data['data'] = input('data');
  189. $checkResult = $this->validate($data,
  190. [
  191. ['data', 'require', '参数不能为空'],
  192. ]);
  193. if (true !== $checkResult) {
  194. $this->result('', 0, $checkResult, 'json');
  195. }
  196. if (!$data = json_decode(opensslDecrypt($data['data']), true)) {
  197. $this->result('', 0, '订单不存在', 'json');
  198. }
  199. $this->assign('data', $data);
  200. return $this->fetch();
  201. }
  202. public function recharge()
  203. {
  204. $this->setPreUrl();
  205. $this->_isLogin();
  206. if (is_mobile_request()) {
  207. $url = MOBILE_SITE_DOMAIN . '/coin/recharge.html?' . http_build_query(input());
  208. header("Location: $url");
  209. exit();
  210. }
  211. $token = input('token');
  212. $token = str_ireplace(" ", "+", $token);
  213. if ($token) {
  214. try {
  215. //聚合渠道时,$sub_username对应的值是mg_username
  216. list($userid2, $username2, $gameid2, $sub_username, $token_random, $type) = explode('|', auth_code($token, "DECODE", Env::get('auth_key')));
  217. // var_dump($userid2, $username2, $gameid2,$sub_username,$token_random,$type);die();
  218. $redisTokenRandom = Cache::store('default')->get('token|' . $type . '|' . $userid2 . '|' . $gameid2);
  219. $this->assign('username2', $username2);
  220. } catch (Exception $e) {
  221. $username2 = '';
  222. }
  223. } else {
  224. $username2 = '';
  225. }
  226. $this->assign('username2', $username2);
  227. return $this->fetch();
  228. }
  229. public function getCoin(){
  230. if (session('front_userid')){
  231. model('MemberCoinInfo')->releaseCoin(session('front_userid'));
  232. $userinfo = model('members')->field('id,amount')->where('id',session('front_userid'))->find();
  233. $this->jsonResult($userinfo, 1,'获取成功');
  234. }else{
  235. $this->jsonResult(['id'=>'','amount'=>'0'], 1,'获取成功');
  236. }
  237. }
  238. public function airwallex()
  239. {
  240. $pay = new AirwallexPay();
  241. $pay->getToken();
  242. // $money = input('money', 0, 'intval');
  243. $orderid = input('orderid', '');
  244. $goods = urldecode(input('goods', ''));
  245. $urltype = input('urltype',1);
  246. $money = cache('memberCoin:real_amount:'.$orderid);
  247. if($urltype == 1){
  248. $return_url = 'https://www.46yx.com/coin_airwallex/recharge.html';
  249. }elseif($urltype == 3){
  250. $return_url = "https://" . HTTP_HOST_URL . "/v1.pay_return/pay_success_airwallex.html";
  251. }
  252. if($money<0){
  253. echo 'money err'; exit();
  254. }
  255. if(!$orderid){
  256. echo 'orderid err'; exit();
  257. }
  258. $result = $pay->createOrder($money, $orderid,$return_url);
  259. $result['goods'] = $goods;
  260. $this->assign('result', $result);
  261. $this->assign('orderid', $orderid);
  262. return $this->fetch();
  263. }
  264. }