Weapp.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\weapp\api\controller;
  11. use addon\weapp\model\Config;
  12. use addon\weapp\model\Message;
  13. use app\api\controller\BaseApi;
  14. use addon\weapp\model\Weapp as WeappModel;
  15. class Weapp extends BaseApi
  16. {
  17. /**
  18. * 获取openid
  19. */
  20. public function authCodeToOpenid()
  21. {
  22. $weapp_model = new WeappModel($this->site_id);
  23. $res = $weapp_model->authCodeToOpenid($this->params);
  24. return $this->response($res);
  25. }
  26. /**
  27. * 获取消息模板id(最多三条)
  28. */
  29. public function messageTmplIds(){
  30. $keywords = $this->params['keywords'] ?? '';
  31. $message = new Message();
  32. $res = $message->getMessageTmplIds($this->site_id, $keywords);
  33. return $this->response($res);
  34. }
  35. /*
  36. * 获取小程序码
  37. */
  38. public function qrcode(){
  39. $config_model = new Config();
  40. $config = $config_model->getWeappConfig($this->site_id);
  41. $qrcode = $config['data']['value']['qrcode'] ?? '';
  42. return $this->response($this->success($qrcode));
  43. }
  44. /**
  45. * 分享
  46. * @return false|string
  47. */
  48. public function share()
  49. {
  50. /*$config_model = new Config();
  51. $config = $config_model->getShareConfig($this->site_id, 'shop');
  52. $share_config = $config['data']['value'];*/
  53. $this->checkToken();
  54. //页面路径
  55. $path = $this->params['path'] ?? '';
  56. //分享配置
  57. $share_config = [];
  58. $share_data = event('WeappShareData', [
  59. 'path' => $path,
  60. 'site_id' => $this->site_id,
  61. 'member_id' => $this->member_id,
  62. ], true);
  63. if(!empty($share_data)){
  64. $share_config['permission'] = $share_data['permission'];
  65. $share_config['data'] = $share_data['data'];
  66. }else{
  67. $share_config['permission'] = [
  68. 'onShareAppMessage' => false,
  69. 'onShareTimeline' => false,
  70. ];
  71. $share_config['data'] = null;
  72. }
  73. return $this->response($this->success($share_config));
  74. }
  75. }