api.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace WY\app\controller;
  3. use WY\app\libs\Controller;
  4. use WY\app\model\Retmsg;
  5. if (!defined('WY_ROOT')) {
  6. exit;
  7. }
  8. class api extends Controller
  9. {
  10. function __construct()
  11. {
  12. parent::__construct();
  13. if ($this->config['is_checkout_jump'] && $this->config['api_jump_url'] && $this->config['api_jump_url'] != $this->req->server('HTTP_HOST') && isset($_REQUEST)) {
  14. $urlstr = '';
  15. foreach ($_REQUEST as $key => $val) {
  16. $urlstr .= $urlstr ? '&' : '';
  17. $urlstr .= $key . '=' . $val;
  18. }
  19. header('location:http://' . $this->config['api_jump_url'] . '/apisubmit?' . $urlstr . '&fromurl=' . $this->req->server('HTTP_REFERER'));
  20. exit;
  21. }
  22. $this->ret = new Retmsg();
  23. $version = '1.0';
  24. $customerid = $this->req->request('customerid');
  25. $sdorderno = $this->req->request('sdorderno');
  26. $total_fee = $this->req->request('total_fee');
  27. $paytype = $this->req->request('paytype');
  28. $notifyurl = $this->req->request('notifyurl');
  29. $bankcode = $this->req->request('bankcode');
  30. $returnurl = $this->req->request('returnurl');
  31. $remark = $this->req->request('remark');
  32. $sign = $this->req->request('sign');
  33. $cardnum = $this->req->request('cardnum');
  34. $fromurl = $this->req->request('fromurl');
  35. if (!isset($_REQUEST) || !$_REQUEST) {
  36. echo $this->ret->put('208', $cardnum ? true : false);
  37. exit;
  38. }
  39. if ($version == '' || $customerid == '' || $total_fee == '' || $sdorderno == '' || $paytype == '' || $notifyurl == '' || $sign == '') {
  40. echo $this->ret->put('200', $cardnum ? true : false);
  41. exit;
  42. }
  43. if (strlen($sdorderno) > 50) {
  44. echo $this->ret->put('203', $cardnum ? true : false);
  45. exit;
  46. }
  47. if ($total_fee > 50000) {
  48. echo $this->ret->put('207', $cardnum ? true : false);
  49. exit;
  50. }
  51. if ($remark && strlen($remark) > 50) {
  52. echo $this->ret->put('204', $cardnum ? true : false);
  53. exit;
  54. }
  55. if ($this->model()->select()->from('orders')->where(array('fields' => 'userid=? and sdorderno=?', 'values' => array($customerid, $sdorderno)))->count()) {
  56. echo $this->ret->put('205', $cardnum ? true : false);
  57. exit;
  58. }
  59. $this->userData = $this->model()->select()->from('users')->where(array('fields' => 'id=?', 'values' => array($customerid)))->fetchRow();
  60. if (!$this->userData) {
  61. echo $this->ret->put('001', $cardnum ? true : false);
  62. exit;
  63. }
  64. if ($this->userData['is_state'] == '0') {
  65. echo $this->ret->put('002', $cardnum ? true : false);
  66. exit;
  67. }
  68. if ($this->userData['is_state'] == '2') {
  69. echo $this->ret->put('003', $cardnum ? true : false);
  70. exit;
  71. }
  72. if ($this->userData['is_paysubmit'] == '0') {
  73. echo $this->ret->put('104', $cardnum ? true : false);
  74. exit;
  75. }
  76. if ($this->userData['is_verify_siteurl']) {
  77. $userInfo = $this->model()->select('siteurl')->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($customerid)))->fetchRow();
  78. if ($userInfo) {
  79. $fromUrl = $this->req->server('HTTP_REFERER');
  80. if (strpos($fromUrl, $userInfo['siteurl']) === false) {
  81. echo $this->ret->put('206', $cardnum ? true : false);
  82. exit;
  83. }
  84. }
  85. }
  86. if ($paytype == 'bank') {
  87. if ($bankcode == '') {
  88. echo $this->ret->put('501', $cardnum ? true : false);
  89. exit;
  90. }
  91. if (!($acb = $this->model()->select()->from('acb')->where(array('fields' => 'code=?', 'values' => array($bankcode)))->fetchRow())) {
  92. echo $this->ret->put('503', $cardnum ? true : false);
  93. exit;
  94. }
  95. if ($acb['is_state'] == '1') {
  96. echo $this->ret->put('502', $cardnum ? true : false);
  97. exit;
  98. }
  99. }
  100. $this->params = array('version' => $version, 'customerid' => $customerid, 'sdorderno' => $sdorderno, 'total_fee' => number_format($total_fee, 2, '.', ''), 'paytype' => $paytype, 'bankcode' => $bankcode, 'notifyurl' => $notifyurl, 'returnurl' => $returnurl, 'remark' => $remark, 'sign' => $sign, 'cardnum' => $cardnum, 'fromurl' => $fromurl);
  101. }
  102. }
  103. ?>