notify.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. error_reporting(0);
  3. define('IN_MOBILE', true);
  4. if(!empty($_POST)) {
  5. $out_trade_no = $_POST['out_trade_no'];
  6. require '../../framework/bootstrap.inc.php';
  7. load()->web('common');
  8. load()->classs('coupon');
  9. $_W['uniacid'] = $_W['weid'] = intval($_POST['body']);
  10. $_W['uniaccount'] = $_W['account'] = uni_fetch($_W['uniacid']);
  11. $_W['acid'] = $_W['uniaccount']['acid'];
  12. $setting = uni_setting($_W['uniacid'], array('payment'));
  13. if ($_POST['body'] == 'site_store') {
  14. $setting['payment'] = setting_load('store_pay');
  15. $setting['payment'] = $setting['payment']['store_pay'];
  16. }
  17. if(is_array($setting['payment'])) {
  18. $alipay = $setting['payment']['alipay'];
  19. if(!empty($alipay)) {
  20. $prepares = array();
  21. foreach($_POST as $key => $value) {
  22. if($key != 'sign' && $key != 'sign_type') {
  23. $prepares[] = "{$key}={$value}";
  24. }
  25. }
  26. sort($prepares);
  27. $string = implode($prepares, '&');
  28. $string .= $alipay['secret'];
  29. $sign = md5($string);
  30. if($sign == $_POST['sign']) {
  31. $_POST['query_type'] = 'notify';
  32. WeUtility::logging('pay-alipay', var_export($_POST, true));
  33. $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniontid`=:uniontid';
  34. $params = array();
  35. $params[':uniontid'] = $out_trade_no;
  36. $log = pdo_fetch($sql, $params);
  37. if(!empty($log) && $log['status'] == '0' && ($_POST['total_fee'] == $log['card_fee'])) {
  38. $log['transaction_id'] = $_POST['trade_no'];
  39. $record = array();
  40. $record['status'] = '1';
  41. pdo_update('core_paylog', $record, array('plid' => $log['plid']));
  42. if ($log['is_usecard'] == 1 && !empty($log['encrypt_code'])) {
  43. $coupon_info = pdo_get('coupon', array('id' => $log['card_id']), array('id'));
  44. $coupon_record = pdo_get('coupon_record', array('code' => $log['encrypt_code'], 'status' => '1'));
  45. load()->model('activity');
  46. $status = activity_coupon_use($coupon_info['id'], $coupon_record['id'], $log['module']);
  47. }
  48. $site = WeUtility::createModuleSite($log['module']);
  49. if(!is_error($site)) {
  50. $method = 'payResult';
  51. if (method_exists($site, $method)) {
  52. $ret = array();
  53. $ret['weid'] = $log['weid'];
  54. $ret['uniacid'] = $log['uniacid'];
  55. $ret['result'] = 'success';
  56. $ret['type'] = $log['type'];
  57. $ret['from'] = 'notify';
  58. $ret['tid'] = $log['tid'];
  59. $ret['uniontid'] = $log['uniontid'];
  60. $ret['transaction_id'] = $log['transaction_id'];
  61. $ret['user'] = $log['openid'];
  62. $ret['fee'] = $log['fee'];
  63. $ret['is_usecard'] = $log['is_usecard'];
  64. $ret['card_type'] = $log['card_type'];
  65. $ret['card_fee'] = $log['card_fee'];
  66. $ret['card_id'] = $log['card_id'];
  67. $site->$method($ret);
  68. exit('success');
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. exit('fail');