MiniProgramSDK.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace app\common\util\wechat;
  3. use app\common\util\SingleObjectClass;
  4. use EasyWeChat\Factory;
  5. use think\Log;
  6. /**
  7. * 微信小程序实例化对象
  8. * Class MiniProgramSDK
  9. * @package app\common\util
  10. */
  11. class MiniProgramSDK extends SingleObjectClass
  12. {
  13. protected $app;
  14. /**
  15. * 构造函数
  16. * MiniProgramSDK constructor.
  17. */
  18. public function __construct()
  19. {
  20. $miniProgramConfig = WxAccountConfig::getMiniProgramConfig();//获取小程序配置
  21. $this->app = Factory::miniProgram($miniProgramConfig);
  22. $cache = new WechatCache();
  23. $this->app->rebind('cache', $cache);
  24. Log::record($cache);
  25. }
  26. /**
  27. * 获取小程序接口实例
  28. * @return \EasyWeChat\MiniProgram\Application
  29. */
  30. public function getApp()
  31. {
  32. return $this->app;
  33. }
  34. public function getPhoneNumber($code){
  35. $params = [
  36. 'code' => $code
  37. ];
  38. return $this->app->live->httpPostJson('wxa/business/getuserphonenumber', $params);
  39. }
  40. }