return.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. if ($_GET['subject'] == '测试支付接口' && $_GET['total_fee'] == 0.01) {
  38. message('支付回调成功!', $_W['siteroot'] . 'web/index.php?c=profile&a=payment', 'success');
  39. }
  40. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
  41. $params = array();
  42. $params[':uniontid'] = $_GET['out_trade_no'];
  43. $log = pdo_fetch($sql, $params);
  44. if (!empty($log)) {
  45. $site = WeUtility::createModuleSite($log['module']);
  46. $method = 'payResult';
  47. if ($log['status'] == 0 && ($_GET['total_fee'] == $log['card_fee'])) {
  48. $log['transaction_id'] = $_GET['trade_no'];
  49. $record = array();
  50. $record['status'] = '1';
  51. pdo_update('core_paylog', $record, array('plid' => $log['plid']));
  52. if ($log['is_usecard'] == 1 && !empty($log['encrypt_code'])) {
  53. $coupon_info = pdo_get('coupon', array('id' => $log['card_id']), array('id'));
  54. $coupon_record = pdo_get('coupon_record', array('code' => $log['encrypt_code'], 'status' => '1'));
  55. load()->model('activity');
  56. $status = activity_coupon_use($coupon_info['id'], $coupon_record['id'], $log['module']);
  57. }
  58. if (!is_error($site)) {
  59. $site->weid = $_W['weid'];
  60. $site->uniacid = $_W['uniacid'];
  61. $site->inMobile = true;
  62. if (method_exists($site, $method)) {
  63. $ret = array();
  64. $ret['weid'] = $log['weid'];
  65. $ret['uniacid'] = $log['uniacid'];
  66. $ret['result'] = 'success';
  67. $ret['type'] = $log['type'];
  68. $ret['from'] = 'notify';
  69. $ret['tid'] = $log['tid'];
  70. $ret['uniontid'] = $log['uniontid'];
  71. $ret['transaction_id'] = $log['transaction_id'];
  72. $ret['user'] = $log['openid'];
  73. $ret['fee'] = $log['fee'];
  74. $ret['is_usecard'] = $log['is_usecard'];
  75. $ret['card_type'] = $log['card_type'];
  76. $ret['card_fee'] = $log['card_fee'];
  77. $ret['card_id'] = $log['card_id'];
  78. $site->$method($ret);
  79. }
  80. }
  81. }
  82. if(!is_error($site)){
  83. $ret['tid'] = $log['tid'];
  84. $ret['result'] = 'success';
  85. $ret['from'] = 'return';
  86. $site->$method($ret);
  87. exit;
  88. }
  89. } else {
  90. $order = pdo_get('site_store_order', array('orderid' => $_GET['out_trade_no']));
  91. if (!empty($order)) {
  92. if ($order['type'] == 1) {
  93. pdo_update('site_store_order', array('type' => 3), array('orderid' => $_GET['out_trade_no']));
  94. }
  95. cache_build_account_modules($order['uniacid']);
  96. header('Location: ./index.php?c=site&a=entry&direct=1&m=store&do=orders');
  97. exit;
  98. }
  99. }
  100. }
  101. } else {
  102. message('支付异常,请返回微信客户端查看订单状态或是联系管理员', '', 'error');
  103. }