Wechat.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\active\controller;
  3. use app\core\model\Channel;
  4. use app\core\model\HongbaoPlan;
  5. use app\core\model\User;
  6. use app\core\model\UserAccount;
  7. use app\core\service\SMS;
  8. use app\core\service\Stat;
  9. use app\core\service\Tongbu;
  10. use think\Cache;
  11. use think\Controller;
  12. use think\Db;
  13. use think\Log;
  14. use think\Request;
  15. use tool\Common;
  16. use wechat\WechatAuth;
  17. use wechat\Wechat as WechatCommon;
  18. class Wechat extends Controller
  19. {
  20. /* public function index() {
  21. $appid = 'wx858c4fed463742d7';
  22. $secret = '6390e4ae8cb2790e080666ae1a6cf5be';
  23. $result = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret);
  24. $result = json_decode($result, true);
  25. $result = file_get_contents('https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$result['access_token'].'&type=jsapi');
  26. $result = json_decode($result, true);
  27. //dump($result);exit;
  28. $data['jsapi_ticket'] = $result['ticket'];
  29. $data['noncestr'] = THINK_START_TIME;
  30. $data['timestamp'] = (int)THINK_START_TIME;
  31. $data['url'] = 'http://www.baidu.com';
  32. $data['signature'] = sha1(http_build_query($data));
  33. $data['appid'] = 'wx858c4fed463742d7';
  34. unset($data['jsapi_ticket']);
  35. header('Content-type:text/json');
  36. echo request()->param('callback').'('.json_encode(Common::rm(1, '操作成功', $data)).')';exit;
  37. }
  38. public function test() {
  39. $signature = $_GET['signature']; //微信加密签名
  40. $timestamp = $_GET['timestamp']; //时间戳
  41. $nonce = $_GET['nonce']; //随机数
  42. $echostr = $_GET['echostr']; //随机字符串
  43. $token = '9GQfeptfROO3v1rjXAwoYjFCMpon8bvS';
  44. $tempArr = array($token,$timestamp,$nonce);
  45. sort($tempArr);
  46. if($signature ==sha1(implode($tempArr))){
  47. echo $echostr;
  48. }else{
  49. exit();
  50. }
  51. }*/
  52. public function index() {
  53. //https://jiaqiancaifu.dahengdian.com/active/wechat/index
  54. //6a204bd89f3c8348afd5c77c717a097a
  55. //O0pHtIhxWbAvcnCWiKPKJeX8tpAcrnTKznh9AvH28cE
  56. $wechatAuth = new WechatAuth('wx5c2cb0242ae05436','0a668108cea8d819fbe48e41b9e0c396');
  57. Log::info($wechatAuth->getAccessToken());
  58. $wechat = new WechatCommon('6a204bd89f3c8348afd5c77c717a097a'/*, 'O0pHtIhxWbAvcnCWiKPKJeX8tpAcrnTKznh9AvH28cE', 'wx5c2cb0242ae05436'*/);
  59. $token = $wechatAuth->getAccessToken();
  60. $data = $wechat->request();
  61. Log::info($data);
  62. $stat = [];
  63. $userCanS = [
  64. 'o1Bky0hQSqcmEeodarB8JP9rfKes',//徐总
  65. 'o1Bky0mQVkNebqyQOqDB5M_Vj3TM',//张奇
  66. 'o1Bky0m4xs9j_PqFyLvfAA3Uwux4',//张江
  67. 'o1Bky0pq59Ho1oP5VzE5YFxLCxgg',//吴总
  68. ];
  69. if(!in_array($data['FromUserName'], $userCanS)) {
  70. exit;
  71. }
  72. if($data['Content'] == '存量') {
  73. $stat = Stat::getStat();
  74. $todayText = '今日总交易额'.$stat['moneySubjectTotal_today']."元\n";
  75. $todayText .= '订单数'.$stat['cangCount_today']."笔\n\n";
  76. $todayText .= '累计交易额'.$stat['moneySubjectTotal_all']."元\n";
  77. $todayText .= '当前存量'.$stat['cunTotal_all']."元\n\n";
  78. $todayText .= '以上信息仅限于新平台 :)';
  79. $wechat->replyText($todayText, $token['access_token']);
  80. }
  81. if($data['Content'] == '交易') {
  82. $list = Db::view('cang','cangID,subjectID,moneySubject,status,addTime,year,investDay,interest,money,userID,isForged,hongbao,yearExt')
  83. ->view('user','userID,trueName,mobile,channelID,isNewInvest,osType','cang.userID=user.userID and user.isForged=0')
  84. ->view('subject','subjectID,title','cang.subjectID=subject.subjectID')
  85. ->view('channel','channelID,name as channelName','user.channelID=channel.channelID', 'left')
  86. ->view('master','trueName as customer,masterID,mobile as customerMobile','master.masterID=cang.masterID', 'left')
  87. //->view('user_hongbao','userHongbaoID,sum(money),sum(interest)','cang.hongbao in (user_hongbao.userHongbaoID)', 'left')
  88. ->whereTime('addTime', 'today')
  89. ->order('cangID desc')
  90. ->select();
  91. $todayText = '';
  92. foreach ($list as $k=>$item) {
  93. $list[$k]['addTime'] = Common::timetodate($list[$k]['addTime']);
  94. $list[$k]['money'] = (int)($list[$k]['money'] / 100);
  95. $list[$k]['moneySubject'] = (int)($list[$k]['moneySubject'] / 100);
  96. $list[$k]['interest'] = Common::price2($list[$k]['interest'] / 100);
  97. $list[$k]['mobile'] = Common::mobileAsterisk($list[$k]['mobile']);
  98. if($list[$k]['osType'] == 1) {
  99. $list[$k]['osType'] = 'ios';
  100. }
  101. else if($list[$k]['osType'] == 2) {
  102. $list[$k]['osType'] = 'android';
  103. }
  104. else if($list[$k]['osType'] == 3) {
  105. $list[$k]['osType'] = 'pc';
  106. }
  107. else if($list[$k]['osType'] == 4) {
  108. $list[$k]['osType'] = 'wap';
  109. }
  110. $list[$k]['moneyHongbao'] = $list[$k]['moneySubject'] - $list[$k]['money'];
  111. $todayText .= "\n\n".$list[$k]['moneySubject'].'元 '.$list[$k]['mobile'].' '.$list[$k]['trueName']."\n";
  112. $todayText .= $list[$k]['title'].' '.$list[$k]['investDay'].'天 '."\n";
  113. $todayText .= $list[$k]['addTime']."\n";
  114. $todayText .= '渠道:'.$list[$k]['osType'].' '.$list[$k]['channelName']."\n\n";
  115. $todayText .= '--------------------------------';
  116. /*$todayText .= '订单数'.$stat['cangCount_today']."笔\n\n";
  117. $todayText .= '累计交易额'.$stat['moneySubjectTotal_all']."元\n";
  118. $todayText .= '当前存量'.$stat['cunTotal_all']."元\n\n";
  119. $todayText .= '以上信息仅限于新平台 :)';*/
  120. }
  121. $todayText .= "\n\n".'以上交易发生于 '.Common::timetodate(THINK_START_TIME, 0)."\n";
  122. $todayText .= '以上信息仅限于新平台 :)';
  123. $wechat->replyText($todayText, $token['access_token']);
  124. }
  125. /*$wechat->replyText($data['Content'], $token['access_token']);
  126. $wechat->replyText($data['Content'], $token['access_token']);
  127. $wechat->replyText($data['Content'], $token['access_token']);
  128. $wechat->replyText($data['Content'], $token['access_token']);
  129. $wechat->replyText($data['Content'], $token['access_token']);
  130. $wechat->replyText($data['Content'], $token['access_token']);
  131. $wechat->replyText($data['Content'], $token['access_token']);*/
  132. //$wechat->
  133. }
  134. }