MpnotifyController.class.php 1.6 KB

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