TestQRcode.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. declare(strict_types=1);
  3. use PHPUnit\Framework\TestCase;
  4. /**
  5. * Created by PhpStorm.
  6. * User: stanley-king
  7. * Date: 2017/5/20
  8. * Time: 下午4:09
  9. */
  10. define('APP_ID', 'test');
  11. define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
  12. require_once(BASE_ROOT_PATH . '/global.php');
  13. require_once(BASE_CORE_PATH . '/lrlz.php');
  14. require_once(BASE_ROOT_PATH . '/fooder.php');
  15. require_once(BASE_HELPER_PATH . '/util_helper.php');
  16. require_once(BASE_HELPER_PATH . '/third_author/signaturer.php');
  17. class TestQRcode extends TestCase
  18. {
  19. public static function setUpBeforeClass(): void
  20. {
  21. Base::run_util();
  22. }
  23. public function testMiniCode()
  24. {
  25. $member_id = 52620;
  26. $queue = Logic('queue');
  27. $queue->makeMemberMiniQrCode(['member_id' => $member_id]);
  28. $url = $this->mini_code($member_id);
  29. }
  30. public function testMakeChannel()
  31. {
  32. $channels = [1000,1001]; //第一次1000块钱的线上推广
  33. $leaflets = [2000,2001]; //传单
  34. $group = [3000,3001,3002]; //传单
  35. $ald = [4000,4001,4002]; //传单
  36. $this->makeChannelCode($group);
  37. }
  38. private function makeChannelCode($channels)
  39. {
  40. foreach ($channels as $channel)
  41. {
  42. $resp = thrid_author\signaturer::instance()->minicode("/pages/index/index?channel={$channel}",430);
  43. if(!empty($resp))
  44. {
  45. $save_path = BASE_ROOT_PATH . "/test/channel/{$channel}.png";
  46. $length = file_put_contents($save_path,$resp);
  47. if(!$length) {
  48. Log::record("Cannot write file: {$save_path}",Log::ERR);
  49. }
  50. else {
  51. Log::record("Create channel image success.",Log::DEBUG);
  52. $share_path = BASE_ROOT_PATH . "/test/channel/share-{$channel}.png";
  53. $this->create_shareimage($save_path,$share_path);
  54. }
  55. }
  56. }
  57. return false;
  58. }
  59. private function create_shareimage($mini_path,$share_path)
  60. {
  61. $back_img = BASE_RESOURCE_PATH . '/mobile/member/images/share.jpg';
  62. $back = $this->create_image($back_img);
  63. $mini = $this->create_image($mini_path);
  64. $dest = imagecreatetruecolor(imagesx($back), imagesy($back));
  65. imagecopy($dest,$back, 0, 0, 0,0, imagesx($back), imagesy($back));
  66. imagecopyresized($dest,$mini, 30, 750, 0,0, 168,168,imagesx($mini), imagesy($mini));
  67. imagepng($dest, $share_path);
  68. }
  69. private function create_image($file)
  70. {
  71. $imagetype = exif_imagetype($file);
  72. if ($imagetype === false) {
  73. return false;
  74. }
  75. switch ($imagetype)
  76. {
  77. case IMAGETYPE_GIF:
  78. $image = @imagecreatefromgif($file);
  79. break;
  80. case IMAGETYPE_JPEG:
  81. case IMAGETYPE_JPEG2000:
  82. $image = @imagecreatefromjpeg($file);
  83. break;
  84. case IMAGETYPE_PNG:
  85. $image = @imagecreatefrompng($file);
  86. break;
  87. case IMAGETYPE_BMP:
  88. $image = @imagecreatefrombmp($file);
  89. break;
  90. default:
  91. return false;
  92. }
  93. return $image;
  94. }
  95. public function testSendInviter()
  96. {
  97. $inviter_id = 52641;
  98. $invitee_id = 52638;
  99. $queue_logic = Logic('queue');
  100. $queue_logic->sendInviterSubMsg(['inviter_id' => $inviter_id,'invitee_id' => $invitee_id]);
  101. $openid = 'ocimY5Bi5voa71ejczOUmxqsDgtU';
  102. $tmpid = 'zBNktaey9EM2DcBzUNsjnAan2NvYpj_nKZDY__f9pGA';
  103. $time = '2020年8月7日';
  104. $data = ['thing4' => ['value' => '江南'], 'time3' => ['value' => "{$time}"]];
  105. thrid_author\signaturer::instance()->send_submsg($openid,$tmpid,'pages/index/index',$data);
  106. }
  107. private function mini_code($uid)
  108. {
  109. $passwd = util::passwd;
  110. $name = md5("{$uid}.{$passwd}") . ".png";
  111. $save_path = BASE_UPLOAD_PATH . DS . ATTACH_MINI_QRCODE . DS . $name;
  112. $url = UPLOAD_SITE_URL . DS . ATTACH_MINI_QRCODE . DS . $name;
  113. if(!file_exists($save_path)) {
  114. QueueClient::push('makeMemberMiniQrCode',['member_id' => $uid]);
  115. }
  116. return $url;
  117. }
  118. public function testPgenA()
  119. {
  120. for ($i = 0; $i < 1000;$i++) {
  121. $save_path = BASE_UPLOAD_PATH . DS.ATTACH_MQRCODE.DS . "{$i}.png";
  122. util::qrcode("http://www.baidu.com","{$i}.png");
  123. }
  124. }
  125. public function testPgenB()
  126. {
  127. for ($i = 1000; $i < 2000;$i++) {
  128. $save_path = BASE_UPLOAD_PATH . DS.ATTACH_MQRCODE.DS . "{$i}.png";
  129. util::qrcode("http://www.baidu.com","{$i}.png");
  130. }
  131. }
  132. public function testPgenC()
  133. {
  134. $bonus_urls = 'http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=37011497008878285022,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=49871497008878288715,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=33191497008878290461,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=82431497008878291960,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=75231497008878293546,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=44051497008878295127,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=53821497008878296732,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=86091497008878298565,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=74421497008878300374,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=14151497008878302183,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=32051497008878303995,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=20181497008878305885,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=21191497008878307698,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=98471497008878309606,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=65191497008878310999,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=74271497008878312456,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=73931497008878314075,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=34831497008878315481,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=89881497008878316845,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=22671497008878318517,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=83171497008878320622,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=64211497008878322835,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=46141497008878324900,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=66361497008878326428,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=70031497008878328081,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=63311497008878329563,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=48021497008878331028,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=57461497008878332611,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=53811497008878334176,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=35381497008878335685,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=60581497008878337530,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=40351497008878339039,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=34101497008878340555,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=45241497008878342056,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=99571497008878343781,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=98201497008878345332,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=11161497008878346835,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=50641497008878348356,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=31871497008878349868,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=10441497008878351341,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=86001497008878353114,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=84661497008878354491,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=66581497008878355813,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=51331497008878357564,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=50671497008878359373,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=24191497008878361338,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=47561497008878363350,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=93111497008878365557,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=35871497008878367456,http://p.lrlz.com/mobile/index.php?act=bonusex&op=open&client_type=wap&type_sn=39991497008878369137';
  135. $urls = explode(',',$bonus_urls);
  136. $i = 0;
  137. foreach ($urls as $url)
  138. {
  139. $save_path = "/Users/stanley-king/Desktop/qrcode/{$i}.png";
  140. util::qrcode_path($url,$save_path);
  141. $i++;
  142. }
  143. }
  144. public function testPgenD()
  145. {
  146. $roomid = 37;
  147. $inviter = 39623;
  148. require_once(BASE_ROOT_PATH . '/helper/url_helper.php');
  149. // $url = url_helper::room_invite_url($roomid,$inviter);
  150. $url = "http://192.168.0.131/mobile/index.php?act=member_talk&op=qr_invite&client_type=ajax&room_id=37&inviter=39623&relay_id=0";
  151. $save_path = "/Users/huangdong/work/shopnc/data/upload/room/qrcodes/{$roomid}_{$inviter}.png";
  152. if(!file_exists($save_path)){
  153. util::qrcode_path($url,$save_path);
  154. }
  155. // unlink($save_path);
  156. }
  157. }