paymentkp.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. defined('IN_WEB') or die('Include Error!');
  3. /**
  4. * Huawei本地支付
  5. */
  6. /**
  7. * 靠谱支付
  8. * User: Administrator
  9. * Date: 2018/6/19
  10. * Time: 12:27
  11. */
  12. class ModelPaymentkp
  13. {
  14. private $appidEUR = '60001002';//欧版的appid
  15. private $_signKey = 'EEF1AD1A-9AA0.40D1-926d!11618fbbd7c5!';
  16. /**
  17. * 靠谱发货接口
  18. */
  19. public function deliveryKaopuPay($param){
  20. // oo::logs()->debug3('param'.json_encode($param));
  21. $appid = $param['appid'] ?? 0;
  22. $username = $param['username'] ?? '';
  23. $kpordernum = $param['kpordernum'] ?? '';
  24. $ywordernum = $param['ywordernum'] ?? '';
  25. $amount = $param['amount'] ?? 0;
  26. $data['username'] = $username;//靠谱用户在 CP 的账号唯一标识
  27. $data['kpordernum'] = $kpordernum;//靠谱订单 ID
  28. $data['ywordernum'] = $ywordernum;//CP 订单 ID
  29. $data['status'] = intval($param['status'] ?? 0);//订单状态 1 为成功,其他为失败
  30. $data['paytype'] = $param['paytype'] ?? '';//充值方式
  31. $data['amount'] = $amount;//成功充值金额(分)
  32. $data['gameserver'] = urldecode($param['gameserver'] ?? '');//区服名称(url 编码传输)
  33. $data['errdesc'] = $param['errdesc'] ?? '';//(该字段始终传空)
  34. $data['paytime'] = $param['paytime'] ?? '';//充值成功时间yyyyMMddHHmmss
  35. $data['gamename'] = urldecode($param['gamename'] ?? '');//游戏名称(url 编码传输)
  36. $signKey = $this->_signKey;
  37. $data['signKey'] = $signKey;
  38. $md5Sign = $this->md5Str($data);
  39. $sign = $param['sign'];
  40. if(empty($username) || empty($ywordernum) || $amount <= 0) {
  41. oo::logs()->debug3('参数异常 param:'.json_encode($param),'kpPaymentFail.php');
  42. return $this->responsePayment(1004, '参数异常');
  43. }
  44. if(empty($sign) || $sign != $md5Sign){
  45. oo::logs()->debug3('验签失败 param:'.json_encode($param),'kpPaymentFail.php');
  46. oo::logs()->debug3('验签的sign:'.$sign.' md5Sign:'.$md5Sign, 'kpPaymentFail.php');
  47. return $this->responsePayment(1002,'验签失败');
  48. }
  49. if($data['status'] !== 1) {
  50. oo::logs()->debug3('充值失败 param:'.json_encode($param),'kpPaymentFail.php');
  51. return $this->responsePayment(1000, '充值失败');
  52. }
  53. $dbGoods = oo::commonOprModel('goods')->getGoodsInfoByOrderId($data['ywordernum']);
  54. if(empty($dbGoods) || !isset($dbGoods['uid'])) {
  55. oo::logs()->debug3('订单不存在 param:'.json_encode($param).' dbgoods:'.json_encode($dbGoods) ,'kpPaymentFail.php');
  56. return $this->responsePayment(1003, '订单不存在');
  57. }
  58. //获取靠谱用户的uid
  59. $uid = $this->getKPUid($username);
  60. if (empty($dbGoods) || empty($uid) || $uid != $dbGoods['uid']) {//验证用户对不对
  61. oo::logs()->debug3('用户不正确 param:'.json_encode($param).' dbgoods:'.json_encode($dbGoods),'kpPaymentFail.php');
  62. return $this->responsePayment(1006, '用户不存在');
  63. }
  64. if($appid == $this->appidEUR) {
  65. $pusd = ($dbGoods['gpriceEur'] ?? 0) * 100;//欧版的按欧分算
  66. }else {
  67. $pusd = ($dbGoods['sl_pusd'] ?? 0) * 100;//美版的按美分算
  68. }
  69. if($pusd <= 0 || $pusd != $amount) { //验证支付金额对不对
  70. oo::logs()->debug3('商品价格错误 param:'.json_encode($param).' dbgoods:'.json_encode($dbGoods),'kpPaymentFail.php');
  71. return $this->responsePayment(1009, '金额不正确');
  72. }
  73. $uid = $dbGoods['uid'];
  74. $pubDeliveryRet = oo::commonOprModel('payment')->pubDelivery($uid, $ywordernum, $kpordernum);
  75. if( $pubDeliveryRet === true || $pubDeliveryRet === -3 ){//发货成功或者是已发货的订单,则返回正确
  76. return $this->responsePayment(1000, '处理成功');
  77. }
  78. return $this->responsePayment(1005, '系统异常');
  79. }
  80. //对参数md5加密
  81. public function md5Str($data)
  82. {
  83. $str = '';
  84. foreach ($data as $v) {
  85. $str = $str.'|'.$v;
  86. }
  87. $str = ltrim($str, '|');
  88. return md5($str);
  89. }
  90. /**
  91. * 返回支付发货结果
  92. * @param $code
  93. * @param $signKey
  94. * @param $msg
  95. * @return string
  96. */
  97. public function responsePayment($code, $msg)
  98. {
  99. $str = $code.'|'.$this->_signKey;
  100. $data['msg'] = $msg;
  101. $data['code'] = $code;
  102. $data['sign'] = md5($str);
  103. return $data;
  104. }
  105. /**
  106. * 通过kpid获取uid
  107. * @param $kpid
  108. * @return mixed
  109. */
  110. public function getKPUid($kpid)
  111. {
  112. //2.27-wsc-注释以下四行
  113. // $table = otable::kaopu();
  114. // $sql = "SELECT uid FROM {$table} WHERE kpid = '{$kpid}' LIMIT 1";
  115. // $ret = oo::commonOprDb('common')->getOne($sql, 1);
  116. // return intval($ret['uid'] ?? 0);
  117. }
  118. }