Twothreethree.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace app\api\complex;
  3. use ComplexThree\JuLe\joloRsa;
  4. /**
  5. * 233乐园
  6. */
  7. class Twothreethree implements ComplexInterface
  8. {
  9. private $channel = 'twothreethree';
  10. /**
  11. * ## 登陆 - 校验
  12. *
  13. * @param $data
  14. * @param $polyChannelGame
  15. *
  16. * @return false
  17. */
  18. public function getSpecialParam($data, $polyChannelGame = [])
  19. {
  20. return $data['user_id'];
  21. }
  22. // ## 登陆 - 登陆
  23. public function checkLogin($data, $polyChannelGame = [])
  24. {
  25. // 参数:user_id = uid, extparam = sid
  26. if (!isset($data['user_id']) || !isset($data['extparam'])) {
  27. return false;
  28. }
  29. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  30. return false;
  31. }
  32. $param = [
  33. 'uid' => $data['user_id'],
  34. 'sid' => $data['extparam'],
  35. ];
  36. ksort($param);
  37. $string = "";
  38. foreach ($param as $k => $v) {
  39. if($k == 'sign' || $v === '' || $v === null){
  40. continue;
  41. }
  42. if ($string) {
  43. $string .= "&{$k}={$v}";
  44. } else {
  45. $string = "{$k}={$v}";
  46. }
  47. }
  48. $string .= "&key=".$channelConfig['appSecret'];
  49. $sign = strtoupper(md5($string));
  50. $header = [
  51. 'Content-Type: application/json',
  52. 'APPKEY: '.$channelConfig['appKey'],
  53. 'SIGN: '.$sign,
  54. ];
  55. $param = json_encode($param);
  56. $res = getHttpPost('https://openapi.metaapp.cn/v2/user/auth', $param, $header);
  57. $res = json_decode($res, true);
  58. if ($res['code'] == 200) {
  59. return true;
  60. } else {
  61. return false;
  62. }
  63. }
  64. // ## 回调 - 效验
  65. public function paySign($data, $polyChannelGame = [])
  66. {
  67. $param = [
  68. 'tradeNo' => $data['tradeNo'], // 233平台对应的交易订单编号(具备唯一性)
  69. 'cpOrderId' => $data['cpOrderId'], // 供应商交易订单id(由供应商下单后出传入)
  70. 'productCode' => $data['productCode'], // 商品编号(供应商下单时提供)
  71. 'productName' => $data['productName'], // 商品名称(供应商下单时提供)
  72. 'productPrice' => $data['productPrice'], // 商品单价(单位:分【人民币分】)
  73. 'count' => $data['count'], // 订单购买购买数量
  74. 'nonce' => $data['nonce'], // 随机安全码(无业务意义,增加接口安全随机性)
  75. 'amount' => $data['amount'], // 订单原值金额(单位:分【人民币】),建议服务端做一下金额校验,避免被刷
  76. 'couponDeductAmount' => $data['couponDeductAmount'], // 优惠券抵扣金额(因优惠券而优惠的金额)(单位:分【人民币】),当该笔交易未使用优惠券时,值为0
  77. 'extra' => $data['extra']??'', // 扩展透传参数,当CP交易系统下单未提供扩展字段时,该字段为空
  78. 'sign' => $data['sign']
  79. ];
  80. if (!$channelConfig = json_decode($polyChannelGame['param'], true)) {
  81. return false;
  82. }
  83. ksort($param);
  84. $param['secret'] = $channelConfig['appSecret'];
  85. $string = "";
  86. foreach ($param as $k => $v) {
  87. if($k == 'sign' || $v === '' || $v === null){
  88. continue;
  89. }
  90. if ($string) {
  91. $string .= "&{$k}={$v}";
  92. } else {
  93. $string = "{$k}={$v}";
  94. }
  95. }
  96. $sha1 = sha1($string);
  97. $last32Chars = substr($sha1, -32);
  98. $sign = strtoupper($last32Chars);
  99. if ($param['sign'] == $sign) {
  100. return true;
  101. }
  102. return false;
  103. }
  104. // ## 回调 - 下单参数获取
  105. public function getData($data)
  106. {
  107. if (!isset($data['cpOrderId']) || !isset($data['amount']) || !isset($data['tradeNo'])) {
  108. return false;
  109. }
  110. return [
  111. 'orderid' => $data['cpOrderId'], // 我方聚合订单
  112. 'amount' => formatFenToYuan($data['amount']),// 充值金额(单位:元)
  113. 'sub_orderid' => $data['tradeNo'], // 渠道订单
  114. ];
  115. }
  116. // ## 回调 - 成功返回
  117. public function getSuccess($msg = '')
  118. {
  119. echo json_encode(['code' => 200, 'message' => 'SUCCESS']);
  120. exit();
  121. }
  122. // ## 回调 - 失败返回
  123. public function getFail($msg = '')
  124. {
  125. echo json_encode(['code' => 22101, 'message' => '接口参数验证不通过']);
  126. exit();
  127. }
  128. }