pay.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. define('IN_MOBILE', true);
  7. require '../../framework/bootstrap.inc.php';
  8. require '../../app/common/bootstrap.app.inc.php';
  9. load()->app('common');
  10. load()->app('template');
  11. $sl = $_GPC['ps'];
  12. $params = @json_decode(base64_decode($sl), true);
  13. $setting = uni_setting($_W['uniacid'], array('payment'));
  14. if(!is_array($setting['payment'])) {
  15. exit('没有设定支付参数.');
  16. }
  17. $payment = $setting['payment']['unionpay'];
  18. require '__init.php';
  19. if (!empty($_POST) && verify($_POST) && $_POST['respMsg'] == 'success') {
  20. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
  21. $params = array();
  22. $params[':uniontid'] = $_POST['orderId'];
  23. $log = pdo_fetch($sql, $params);
  24. if(!empty($log) && $log['status'] == '0') {
  25. $log['tag'] = iunserializer($log['tag']);
  26. $log['tag']['queryId'] = $_POST['queryId'];
  27. $record = array();
  28. $record['status'] = 1;
  29. $record['tag'] = iserializer($log['tag']);
  30. pdo_update('core_paylog', $record, array('plid' => $log['plid']));
  31. if($log['is_usecard'] == 1 && $log['card_type'] == 1 && !empty($log['encrypt_code']) && $log['acid']) {
  32. load()->classs('coupon');
  33. $acc = new coupon($log['acid']);
  34. $codearr['encrypt_code'] = $log['encrypt_code'];
  35. $codearr['module'] = $log['module'];
  36. $codearr['card_id'] = $log['card_id'];
  37. $acc->PayConsumeCode($codearr);
  38. }
  39. if($log['is_usecard'] == 1 && $log['card_type'] == 2) {
  40. $log['card_id'] = intval($log['card_id']);
  41. pdo_update('activity_coupon_record', array(
  42. 'status' => 2,
  43. 'usetime' => TIMESTAMP,
  44. 'usemodule' => $log['module'],
  45. ), array(
  46. 'uniacid' => $_W['uniacid'],
  47. 'couponid' => $log['card_id'],
  48. 'uid' => $log['openid'],
  49. ));
  50. }
  51. }
  52. $site = WeUtility::createModuleSite($log['module']);
  53. if(!is_error($site)) {
  54. $method = 'payResult';
  55. if (method_exists($site, $method)) {
  56. $ret = array();
  57. $ret['weid'] = $log['uniacid'];
  58. $ret['uniacid'] = $log['uniacid'];
  59. $ret['result'] = 'success';
  60. $ret['type'] = $log['type'];
  61. $ret['from'] = 'return';
  62. $ret['tid'] = $log['tid'];
  63. $ret['uniontid'] = $log['uniontid'];
  64. $ret['user'] = $log['openid'];
  65. $ret['fee'] = $log['fee'];
  66. $ret['tag'] = $log['tag'];
  67. $ret['is_usecard'] = $log['is_usecard'];
  68. $ret['card_fee'] = $log['card_fee'];
  69. $ret['card_id'] = $log['card_id'];
  70. $site->$method($ret);
  71. exit('success');
  72. }
  73. }
  74. }
  75. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `plid`=:plid';
  76. $paylog = pdo_fetch($sql, array(':plid' => $params['tid']));
  77. if(!empty($paylog) && $paylog['status'] != '0') {
  78. exit('这个订单已经支付成功, 不需要重复支付.');
  79. }
  80. $auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
  81. if($auth != $_GPC['auth']) {
  82. exit('参数传输错误.');
  83. }
  84. $_W['openid'] = intval($paylog['openid']);
  85. $params = array(
  86. 'version' => '5.0.0',
  87. 'encoding' => 'utf-8',
  88. 'certId' => getSignCertId(),
  89. 'txnType' => '01',
  90. 'txnSubType' => '01',
  91. 'bizType' => '000201',
  92. 'frontUrl' => SDK_FRONT_NOTIFY_URL . '?i='.$_W['uniacid'],
  93. 'backUrl' => SDK_BACK_NOTIFY_URL . '?i='.$_W['uniacid'],
  94. 'signMethod' => '01',
  95. 'channelType' => '08',
  96. 'accessType' => '0',
  97. 'merId' => SDK_MERID,
  98. 'orderId' => $paylog['uniontid'],
  99. 'txnTime' => date('YmdHis'),
  100. 'txnAmt' => $paylog['fee'] * 100,
  101. 'currencyCode' => '156',
  102. 'defaultPayType' => '0001',
  103. 'reqReserved' => $_W['uniacid'],
  104. );
  105. sign($params);
  106. $html_form = create_html($params, SDK_FRONT_TRANS_URL);
  107. echo $html_form;