人人商城

return.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. error_reporting(0);
  3. define('IN_MOBILE', true);
  4. if (empty($_GET['out_trade_no'])) {
  5. exit('request failed.');
  6. }
  7. require '../../framework/bootstrap.inc.php';
  8. load()->app('common');
  9. load()->app('template');
  10. $_W['uniacid'] = $_W['weid'] = intval($_GET['body']);
  11. $setting = uni_setting($_W['uniacid'], array('payment'));
  12. if ($_GET['exterface'] == 'create_direct_pay_by_user') {
  13. $setting['payment'] = setting_load('store_pay');
  14. $setting['payment'] = $setting['payment']['store_pay'];
  15. }
  16. if (!is_array($setting['payment'])) {
  17. exit('request failed.');
  18. }
  19. $alipay = $setting['payment']['alipay'];
  20. if (empty($alipay)) {
  21. exit('request failed.');
  22. }
  23. $prepares = array();
  24. foreach ($_GET as $key => $value) {
  25. if ($key != 'sign' && $key != 'sign_type') {
  26. $prepares[] = "{$key}={$value}";
  27. }
  28. }
  29. sort($prepares);
  30. $string = implode($prepares, '&');
  31. $string .= $alipay['secret'];
  32. $sign = md5($string);
  33. if($sign == $_GET['sign']){
  34. $_GET['query_type'] = 'return';
  35. WeUtility::logging('pay-alipay', var_export($_GET, true));
  36. if($_GET['is_success'] == 'T' && ($_GET['trade_status'] == 'TRADE_FINISHED' || $_GET['trade_status'] == 'TRADE_SUCCESS')) {
  37. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
  38. $params = array();
  39. $params[':uniontid'] = $_GET['out_trade_no'];
  40. $log = pdo_fetch($sql, $params);
  41. if (!empty($log)) {
  42. $site = WeUtility::createModuleSite($log['module']);
  43. $method = 'payResult';
  44. if ($log['status'] == 0 && ($_GET['total_fee'] == $log['card_fee'])) {
  45. $log['transaction_id'] = $_GET['trade_no'];
  46. $record = array();
  47. $record['status'] = '1';
  48. pdo_update('core_paylog', $record, array('plid' => $log['plid']));
  49. if ($log['is_usecard'] == 1 && !empty($log['encrypt_code'])) {
  50. $coupon_info = pdo_get('coupon', array('id' => $log['card_id']), array('id'));
  51. $coupon_record = pdo_get('coupon_record', array('code' => $log['encrypt_code'], 'status' => '1'));
  52. load()->model('activity');
  53. $status = activity_coupon_use($coupon_info['id'], $coupon_record['id'], $log['module']);
  54. }
  55. if (!is_error($site)) {
  56. $site->weid = $_W['weid'];
  57. $site->uniacid = $_W['uniacid'];
  58. $site->inMobile = true;
  59. if (method_exists($site, $method)) {
  60. $ret = array();
  61. $ret['weid'] = $log['weid'];
  62. $ret['uniacid'] = $log['uniacid'];
  63. $ret['result'] = 'success';
  64. $ret['type'] = $log['type'];
  65. $ret['from'] = 'notify';
  66. $ret['tid'] = $log['tid'];
  67. $ret['uniontid'] = $log['uniontid'];
  68. $ret['transaction_id'] = $log['transaction_id'];
  69. $ret['user'] = $log['openid'];
  70. $ret['fee'] = $log['fee'];
  71. $ret['is_usecard'] = $log['is_usecard'];
  72. $ret['card_type'] = $log['card_type'];
  73. $ret['card_fee'] = $log['card_fee'];
  74. $ret['card_id'] = $log['card_id'];
  75. $site->$method($ret);
  76. }
  77. }
  78. }
  79. if(!is_error($site)){
  80. $ret['tid'] = $log['tid'];
  81. $ret['result'] = 'success';
  82. $ret['from'] = 'return';
  83. $site->$method($ret);
  84. exit;
  85. }
  86. } else {
  87. $order = pdo_get('site_store_order', array('orderid' => $_GET['out_trade_no']));
  88. if (!empty($order)) {
  89. if ($order['type'] == 1) {
  90. pdo_update('site_store_order', array('type' => 3), array('orderid' => $_GET['out_trade_no']));
  91. }
  92. cache_build_account_modules($order['uniacid']);
  93. header('Location: ./index.php?c=site&a=entry&direct=1&m=store&do=orders');
  94. }
  95. }
  96. }
  97. } else {
  98. message('支付异常,请返回微信客户端查看订单状态或是联系管理员', '', 'error');
  99. }