ByteDanceCode2Session.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\service\byte_dance;
  3. use think\Cache;
  4. class ByteDanceCode2Session implements ByteDanceInterface {
  5. protected $code;
  6. public function setCode($code)
  7. {
  8. $this->code = $code;
  9. return $this;
  10. }
  11. public function get()
  12. {
  13. return ByteDance::httpPost('https://developer.toutiao.com/api/apps/v2/jscode2session',$this->params());
  14. }
  15. protected function params(){
  16. return [
  17. 'appid'=>ByteDance::appId(),
  18. 'secret'=>ByteDance::appSecret(),
  19. 'code'=>$this->code,
  20. ];
  21. }
  22. //新小程序
  23. public function setCodeTwo($code)
  24. {
  25. $this->code = $code;
  26. return $this;
  27. }
  28. public function getTwo()
  29. {
  30. return ByteDance::httpPost('https://developer.toutiao.com/api/apps/v2/jscode2session',$this->paramsTwo());
  31. }
  32. protected function paramsTwo(){
  33. return [
  34. 'appid'=>ByteDance::appIdTwo(),
  35. 'secret'=>ByteDance::appSecretTwo(),
  36. 'code'=>$this->code,
  37. ];
  38. }
  39. //新新小程序
  40. public function setCodeThree($code)
  41. {
  42. $this->code = $code;
  43. return $this;
  44. }
  45. public function getThree()
  46. {
  47. return ByteDance::httpPost('https://developer.toutiao.com/api/apps/v2/jscode2session',$this->paramsThree());
  48. }
  49. protected function paramsThree(){
  50. return [
  51. 'appid'=>ByteDance::appIdThree(),
  52. 'secret'=>ByteDance::appSecretThree(),
  53. 'code'=>$this->code,
  54. ];
  55. }
  56. }