Shunyouios.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * 支付接口(自己聚合自己的星空互娱渠道)控制器
  4. *
  5. */
  6. namespace app\complex\controller;
  7. use app\common\model\PolychannelGame;
  8. use app\common\logic\PayCallback;
  9. use think\Db;
  10. class Shunyouios extends Complex {
  11. protected $channel_mark = 'shunyou';
  12. /**
  13. * 支付处理
  14. */
  15. public function pay()
  16. {
  17. if (empty($_POST)) {
  18. die('请求内容为空');
  19. }
  20. $orderid = trim($_POST['orderId']); //下级渠道的订单号
  21. $uid = trim($_POST['uid']);
  22. $amount = trim($_POST['amount']);
  23. $serverId = trim($_POST['serverId']);
  24. $attach = trim($_POST['extraInfo']);
  25. $test = trim($_POST['test']);
  26. $paytime = trim($_POST['orderTime']);
  27. $billno = trim($_POST['billno']); //这个才是自己聚合层(本级)的订单编号
  28. $sign = trim($_POST['sign']);
  29. if(!$this->checkOrder($attach,$amount)){
  30. log_message('订单不存在或订单金额不一致,orderid='.$orderid,'error',LOG_PATH . '../complexPaylog/');
  31. die('订单不存在或订单金额不一致');
  32. }
  33. $polyChannelGameModel = new PolychannelGame;
  34. $param = $polyChannelGameModel->where(['game_id'=>$this->payInfo['gameid'],'channel_id'=>$this->payInfo['channel_id']])->value('param');
  35. if(empty($param)){
  36. log_message('后台渠道游戏中,用于该游戏的验签参数还未设置,orderid='.$orderid,'error',LOG_PATH . '../complexPaylog/');
  37. die('用于验签的参数还未设置');
  38. }
  39. $param = unserialize($param);
  40. $appkey = $param[$this->payInfo['gameid']];
  41. $str = $orderid.$uid.$serverId.$amount.$attach.$paytime.$billno.$test;
  42. $str.= $appkey;
  43. $thisSign = strtolower(md5($str));
  44. if ($sign != $thisSign) {
  45. log_message('签名校验失败,参数:'.$str.' 生成的签名thisSign='.$thisSign.' 对方的签名:'.$sign,'error',LOG_PATH . '../complexPaylog/');
  46. die('签名校验失败 ' . $thisSign);
  47. }
  48. // 启动事务
  49. Db::startTrans();
  50. try{
  51. $this->updateOrder($attach,$orderid,$paytime);
  52. // 提交事务
  53. Db::commit();
  54. }
  55. catch (\Exception $e) {
  56. // 回滚事务
  57. Db::rollback();
  58. die('订单生成失败'.$e->getMessage());
  59. }
  60. // 【产品确认:测试阶段暂时不用通知CP】通知CP,支付成功
  61. (new PayCallback())->callBackToCp($attach);
  62. die('success');
  63. }
  64. /**
  65. * 二次登录验证
  66. */
  67. public function checklogin()
  68. {
  69. /*
  70. $_POST['appid'] = '100073';
  71. $_POST['uid'] = '122211';
  72. $_POST['token'] = '123213213';
  73. $_POST['time'] = time();
  74. $_POST['sessid'] = '32423432432';
  75. */
  76. if (empty($_POST)) {
  77. die('请求内容为空');
  78. }
  79. $appid = trim($_POST['appid']);
  80. $uid = trim($_POST['uid']);
  81. $token = trim($_POST['token']);
  82. $time = trim($_POST['time']);
  83. $sessid = trim($_POST['sessid']);
  84. $appkeyArrs = array("100071"=>"4b95e2540f940b1df90463ca060dd53c","100073"=>"10bd288640193feb5c8c470dd215e09f");
  85. if(!isset($appkeyArrs{$appid})){
  86. die('APP秘钥未配置');
  87. }
  88. else{
  89. $appkey = $appkeyArrs{$appid};
  90. }
  91. $sign = strtolower(md5($appid.$uid.$token.$sessid.$time.$appkey));
  92. $checkUrl = 'http://apisdk.pdl188.com/Api/Member/CheckLogin';
  93. $response = get_http_response($checkUrl, http_build_query(['appid'=>$appid,'uid'=>$uid,'token'=>$token,'time'=>$time,'sessid'=>$sessid,'sign'=>$sign]));
  94. // var_dump($response);
  95. // $response = json_decode($response,true);
  96. // var_dump($response);
  97. if ($response == 'success'){
  98. die('success');
  99. }
  100. else{
  101. die($response);
  102. }
  103. die('failed');
  104. }
  105. }