pay.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. $now = time();
  41. $log['card_id'] = intval($log['card_id']);
  42. pdo_query('UPDATE ' . tablename('activity_coupon_record') . " SET status = 2, usetime = {$now}, usemodule = '{$log['module']}' WHERE uniacid = :aid AND couponid = :cid AND uid = :uid AND status = 1 LIMIT 1", array(':aid' => $_W['uniacid'], ':uid' => $log['openid'], ':cid' => $log['card_id']));
  43. }
  44. }
  45. $site = WeUtility::createModuleSite($log['module']);
  46. if(!is_error($site)) {
  47. $method = 'payResult';
  48. if (method_exists($site, $method)) {
  49. $ret = array();
  50. $ret['weid'] = $log['uniacid'];
  51. $ret['uniacid'] = $log['uniacid'];
  52. $ret['result'] = 'success';
  53. $ret['type'] = $log['type'];
  54. $ret['from'] = 'return';
  55. $ret['tid'] = $log['tid'];
  56. $ret['uniontid'] = $log['uniontid'];
  57. $ret['user'] = $log['openid'];
  58. $ret['fee'] = $log['fee'];
  59. $ret['tag'] = $log['tag'];
  60. $ret['is_usecard'] = $log['is_usecard'];
  61. $ret['card_fee'] = $log['card_fee'];
  62. $ret['card_id'] = $log['card_id'];
  63. $site->$method($ret);
  64. exit('success');
  65. }
  66. }
  67. }
  68. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `plid`=:plid';
  69. $paylog = pdo_fetch($sql, array(':plid' => $params['tid']));
  70. if(!empty($paylog) && $paylog['status'] != '0') {
  71. exit('这个订单已经支付成功, 不需要重复支付.');
  72. }
  73. $auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
  74. if($auth != $_GPC['auth']) {
  75. exit('参数传输错误.');
  76. }
  77. $_W['openid'] = intval($paylog['openid']);
  78. $params = array(
  79. 'version' => '5.0.0',
  80. 'encoding' => 'utf-8',
  81. 'certId' => getSignCertId(),
  82. 'txnType' => '01',
  83. 'txnSubType' => '01',
  84. 'bizType' => '000201',
  85. 'frontUrl' => SDK_FRONT_NOTIFY_URL . '?i='.$_W['uniacid'],
  86. 'backUrl' => SDK_BACK_NOTIFY_URL . '?i='.$_W['uniacid'],
  87. 'signMethod' => '01',
  88. 'channelType' => '08',
  89. 'accessType' => '0',
  90. 'merId' => SDK_MERID,
  91. 'orderId' => $paylog['uniontid'],
  92. 'txnTime' => date('YmdHis'),
  93. 'txnAmt' => $paylog['fee'] * 100,
  94. 'currencyCode' => '156',
  95. 'defaultPayType' => '0001',
  96. 'reqReserved' => $_W['uniacid'],
  97. );
  98. sign($params);
  99. $html_form = create_html($params, SDK_FRONT_TRANS_URL);
  100. echo $html_form;