MpnotifyController.class.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * lionfish 狮子鱼社区团购系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. class MpnotifyController extends CommonController {
  11. protected function _initialize(){
  12. $this->checkSignature();
  13. }
  14. /**
  15. * @author yj
  16. * @desc 接收微信小程序通知入口
  17. */
  18. public function index()
  19. {
  20. $data = file_get_contents('php://input');
  21. $ins_data = [];
  22. $ins_data['text'] = ( $data );
  23. $ins_data['is_success'] = 1;
  24. $ins_data['type'] = '2';
  25. $ins_data['log'] = date('Y-m-d H:i:s');
  26. M('log')->add($ins_data);
  27. echo 'success';
  28. die();
  29. }
  30. private function checkSignature()
  31. {
  32. if( isset($_GET['echostr']) )
  33. {
  34. $signature = $_GET["signature"];
  35. $timestamp = $_GET["timestamp"];
  36. $nonce = $_GET["nonce"];
  37. $token = D('Home/Front')->get_config_by_name('tradecomponts_token');
  38. $tmpArr = array($token, $timestamp, $nonce);
  39. sort($tmpArr, SORT_STRING);
  40. $tmpStr = implode( $tmpArr );
  41. $tmpStr = sha1( $tmpStr );
  42. if ($tmpStr == $signature ) {
  43. echo $_GET['echostr'];
  44. die();
  45. } else {
  46. return false;
  47. }
  48. }
  49. }
  50. }