SubscribeController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Http\Controllers\WapBrowser\Subscribe;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\WapBrowser\BaseController;
  5. use GuzzleHttp\Client;
  6. use App\Modules\OfficialAccount\Services\OfficialAccountService;
  7. use App\Modules\SendOrder\Services\SendOrderService;
  8. use Cookie;
  9. use Log;
  10. use Hashids;
  11. class SubscribeController extends BaseController
  12. {
  13. protected function getRcodeInfo($appid,$bid,$cid)
  14. {
  15. if($bid && $cid){
  16. $scene_id = sprintf('outer:%s_%s',$bid,$cid);
  17. }else{
  18. $scene_id = 1;
  19. }
  20. $param_need = [
  21. 'gzh_app_id' => $appid,
  22. 'scene_id' => $scene_id,
  23. 'timestamp' => time(),
  24. ];
  25. $param_need['sign'] = $this->getSign($param_need);
  26. $client = new Client(['timeout' => 3.0,]);
  27. try {
  28. Log::info('WapBrowsergetRcodeInfo get qrcode url is:' . 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need));
  29. $qrcode_url_res = $client->request('get', 'https://zsyauth.aizhuishu.com/api/get_qrcode_url?' . http_build_query($param_need))->getBody()->getContents();
  30. if ($qrcode_url_res) {
  31. $qrcode_url = json_decode($qrcode_url_res, true);
  32. if ($qrcode_url['code'] == 1) {
  33. //保存强关时的bid
  34. if (isset($qrcode_url['data']) && !empty($qrcode_url['data'])) {
  35. return $qrcode_url['data'];
  36. }
  37. }
  38. }
  39. } catch (\Exception $e) {
  40. }
  41. return false;
  42. }
  43. /**
  44. * 获取公众号信息
  45. * @param $distribution_channel_id
  46. */
  47. protected function getOfficialAccount()
  48. {
  49. $distribution_channel_id = $this->distribution_channel_id;
  50. $res = OfficialAccountService::canUseOfficialAccountByChannelId(compact('distribution_channel_id'));
  51. Log::info($res);
  52. if (isset($res->nickname) && !empty($res->nickname)) {
  53. Cookie::queue('force_subscribe_name', $res->nickname, env('U_COOKIE_EXPIRE'));
  54. }
  55. return $res;
  56. }
  57. public function subscribeView(Request $request){
  58. $title = '扫一扫';
  59. $send_order_id = Cookie::get('send_order_id');
  60. $bid = $request->get('bid');
  61. $cid = $request->get('cid');
  62. $url = '';
  63. if($send_order_id){
  64. $h5_scheme = env('H5_SCHEME', 'https');
  65. if($bid && $cid){
  66. $bid = Hashids::encode($bid);
  67. $redirect_path = urlencode(sprintf('/reader?bid=%s&cid=%s',$bid,$cid));
  68. $url = $h5_scheme . '://' . str_replace('bsite','site',_domain()). '/yun/'.$send_order_id.'?redirect_path='.$redirect_path;
  69. }else{
  70. $url = $h5_scheme . '://' . str_replace('bsite','site',_domain()). '/yun/'.$send_order_id;
  71. }
  72. $img = '';
  73. return view('wap-browser.subscribe',compact('title','img','url'));
  74. }
  75. $appid = $this->getOfficialAccount();
  76. $bid = $request->get('bid');
  77. $cid = $request->get('cid');
  78. Log::info("this->distribution_channel_id:".$this->distribution_channel_id);
  79. $img = '';
  80. if($appid && $appid->appid){
  81. $img = $this->getRcodeInfo($appid->appid,$bid,$cid);
  82. }
  83. return view('wap-browser.subscribe',compact('title','img','url'));
  84. }
  85. private function getRcodeInfoV2(){
  86. }
  87. }