人人商城

pay.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $_GPC['i'] = !empty($_GPC['i']) ? intval($_GPC['i']) : intval($_GET['extra']);
  9. require '../../app/common/bootstrap.app.inc.php';
  10. load()->app('common');
  11. load()->app('template');
  12. $sl = $_GPC['ps'];
  13. $params = @json_decode(base64_decode($sl), true);
  14. $setting = uni_setting($_W['uniacid'], array('payment'));
  15. if(!is_array($setting['payment'])) {
  16. exit('没有设定支付参数.');
  17. }
  18. $payment = $setting['payment']['baifubao'];
  19. require 'bfb_sdk.php';
  20. if (!empty($_GPC['pay_result']) && $_GPC['pay_result'] == '1') {
  21. $bfb_sdk = new bfb_sdk();
  22. if (true === $bfb_sdk->check_bfb_pay_result_notify()) {
  23. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
  24. $params = array();
  25. $params[':uniontid'] = $_GPC['order_no'];
  26. $log = pdo_fetch($sql, $params);
  27. $site = WeUtility::createModuleSite($log['module']);
  28. if(!is_error($site)) {
  29. $method = 'payResult';
  30. if (method_exists($site, $method)) {
  31. $ret = array();
  32. $ret['weid'] = $log['uniacid'];
  33. $ret['uniacid'] = $log['uniacid'];
  34. $ret['result'] = 'success';
  35. $ret['type'] = $log['type'];
  36. $ret['from'] = 'return';
  37. $ret['tid'] = $log['tid'];
  38. $ret['uniontid'] = $log['uniontid'];
  39. $ret['user'] = $log['openid'];
  40. $ret['fee'] = $log['fee'];
  41. $ret['tag'] = $log['tag'];
  42. $site->$method($ret);
  43. $bfb_sdk->notify_bfb();
  44. exit('success');
  45. }
  46. }
  47. }
  48. }
  49. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `plid`=:plid';
  50. $paylog = pdo_fetch($sql, array(':plid' => $params['tid']));
  51. if(!empty($paylog) && $paylog['status'] != '0') {
  52. exit('这个订单已经支付成功, 不需要重复支付.');
  53. }
  54. $auth = sha1($sl . $paylog['uniacid'] . $_W['config']['setting']['authkey']);
  55. if($auth != $_GPC['auth']) {
  56. exit('参数传输错误.');
  57. }
  58. $_W['openid'] = intval($paylog['openid']);
  59. $bfb_sdk = new bfb_sdk();
  60. $params = array (
  61. 'service_code' => sp_conf::BFB_PAY_INTERFACE_SERVICE_ID,
  62. 'sp_no' => sp_conf::$SP_NO,
  63. 'order_create_time' => date("YmdHis"),
  64. 'order_no' => $paylog['uniontid'],
  65. 'goods_name' => iconv('utf-8', 'gbk', $params['title']),
  66. 'total_amount' => $params['fee'] * 100,
  67. 'currency' => sp_conf::BFB_INTERFACE_CURRENTCY,
  68. 'buyer_sp_username' => $_W['openid'],
  69. 'return_url' => $_W['siteroot'] . 'notify.php',
  70. 'page_url' => $_W['siteroot'] . 'pay.php',
  71. 'pay_type' => '2',
  72. 'bank_no' => '201',
  73. 'expire_time' => date('YmdHis', strtotime('+15 day')),
  74. 'input_charset' => sp_conf::BFB_INTERFACE_ENCODING,
  75. 'version' => sp_conf::BFB_INTERFACE_VERSION,
  76. 'sign_method' => sp_conf::SIGN_METHOD_MD5,
  77. 'extra' => $_W['uniacid'],
  78. );
  79. $order_url = $bfb_sdk->create_baifubao_pay_order_url($params, sp_conf::BFB_PAY_WAP_DIRECT_URL);
  80. if(false !== $order_url) {
  81. echo "<script>window.location=\"" . $order_url . "\";</script>";
  82. exit;
  83. }