rights.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $input = file_get_contents('php://input');
  7. if (preg_match('/(\<\!DOCTYPE|\<\!ENTITY)/i', $input)) {
  8. exit('fail');
  9. }
  10. libxml_disable_entity_loader(true);
  11. $obj = simplexml_load_string($input, 'SimpleXMLElement', LIBXML_NOCDATA);
  12. if($obj instanceof SimpleXMLElement && !empty($obj->FeedBackId)) {
  13. $data = array(
  14. 'openid' => trim($obj->OpenId),
  15. 'appid' => trim($obj->AppId),
  16. 'timestamp' => trim($obj->TimeStamp),
  17. 'msgtype' => trim($obj->MsgType),
  18. 'feedbackid' => trim($obj->FeedBackId),
  19. 'transid' => trim($obj->TransId),
  20. 'reason' => trim($obj->Reason),
  21. 'solution' => trim($obj->Solution),
  22. 'extinfo' => trim($obj->ExtInfo),
  23. 'appsignature' => trim($obj->AppSignature),
  24. 'signmethod' => trim($obj->SignMethod),
  25. );
  26. if (!empty($obj->PicInfo) && !empty($obj->PicInfo->item)) {
  27. foreach ($obj->PicInfo->item as $item) {
  28. $data['picinfo'][] = trim($item->PicUrl);
  29. }
  30. }
  31. require '../../framework/bootstrap.inc.php';
  32. WeUtility::logging('pay-rights', $input);
  33. $_W['uniacid'] = pdo_fetchcolumn("SELECT uniacid FROM ".tablename('account_wechats')." WHERE `key` = :key", array(':key' => $data['appid']));
  34. $setting = uni_setting($_W['uniacid'], array('payment'));
  35. $_W['weid'] = $_W['uniacid'];
  36. if (empty($setting['payment'])) {
  37. exit('failed');
  38. }
  39. $data['appkey'] = $setting['payment']['wechat']['signkey'];
  40. if (!checkSign($data)) {
  41. exit('failed');
  42. }
  43. if ($data['msgtype'] == 'request') {
  44. $insert = array(
  45. 'weid' => $_W['weid'],
  46. 'openid' => $data['openid'],
  47. 'feedbackid' => $data['feedbackid'],
  48. 'transid' => $data['transid'],
  49. 'reason' => $data['reason'],
  50. 'solution' => $data['solution'],
  51. 'remark' => $data['extinfo'],
  52. 'createtime' => $data['timestamp'],
  53. 'status' => 0,
  54. );
  55. pdo_insert('shopping_feedback', $insert);
  56. exit('success');
  57. } elseif ($data['msgtype'] == 'confirm') {
  58. pdo_update('shopping_feedback', array('status' => 1), array('feedbackid' => $data['feedbackid']));
  59. exit('success');
  60. } elseif ($data['msgtype'] == 'reject') {
  61. pdo_update('shopping_feedback', array('status' => 2), array('feedbackid' => $data['feedbackid']));
  62. exit('success');
  63. } else {
  64. exit('failed');
  65. }
  66. }
  67. exit('failed');
  68. function checkSign($data) {
  69. $string = '';
  70. $keys = array('appid', 'timestamp', 'openid', 'appkey');
  71. sort($keys);
  72. foreach($keys as $key) {
  73. $v = $data[$key];
  74. $key = strtolower($key);
  75. $string .= "{$key}={$v}&";
  76. }
  77. $string = sha1(rtrim($string, '&'));
  78. if ($data['appsignature'] == $string) {
  79. return true;
  80. } else {
  81. return false;
  82. }
  83. }