人人商城

url2qr.ctrl.php 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. defined('IN_IA') or exit('Access Denied');
  7. load()->model('account');
  8. load()->func('communication');
  9. load()->library('qrcode');
  10. $dos = array('display', 'change', 'qr', 'chat', 'down_qr');
  11. $do = !empty($_GPC['do']) && in_array($do, $dos) ? $do : 'display';
  12. permission_check_account_user('platform_qr');
  13. $_W['page']['title'] = '长链接转二维码';
  14. if ($do == 'display') {
  15. template('platform/url2qr');
  16. }
  17. if ($do == 'change') {
  18. if ($_W['ispost'] && $_W['isajax']) {
  19. $longurl = trim($_GPC['longurl']);
  20. $token = $_W['account']->getAccessToken();
  21. $url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token={$token}";
  22. $send = array();
  23. $send['action'] = 'long2short';
  24. $send['long_url'] = $longurl;
  25. $response = ihttp_request($url, json_encode($send));
  26. if (is_error($response)) {
  27. $result = error(-1, "访问公众平台接口失败, 错误: {$response['message']}");
  28. }
  29. $result = @json_decode($response['content'], true);
  30. if (empty($result)) {
  31. $result = error(-1, "接口调用失败, 元数据: {$response['meta']}");
  32. } elseif (!empty($result['errcode'])) {
  33. $result = error(-1, "访问微信接口错误, 错误代码: {$result['errcode']}, 错误信息: {$result['errmsg']}");
  34. }
  35. if (is_error($result)) {
  36. iajax(-1, $result['message'], '');
  37. }
  38. iajax(0, $result, '');
  39. } else {
  40. iajax(1, 'error', '');
  41. }
  42. }
  43. if ($do == 'qr') {
  44. $url = $_GPC['url'];
  45. $errorCorrectionLevel = "L";
  46. $matrixPointSize = "5";
  47. QRcode::png($url, false, $errorCorrectionLevel, $matrixPointSize);
  48. exit();
  49. }
  50. if ($do == 'down_qr') {
  51. $qrlink = $_GPC['qrlink'];
  52. $errorCorrectionLevel = "L";
  53. $matrixPointSize = "5";
  54. $qr_pic = QRcode::png($qrlink, false, $errorCorrectionLevel, $matrixPointSize);
  55. $name = random(8);
  56. header('cache-control:private');
  57. header('content-type:image/jpeg');
  58. header('content-disposition: attachment;filename="'.$name.'.jpg"');
  59. readfile($qr_pic);
  60. exit;
  61. }