Crypt.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\extra\dyLife;
  3. use yzh52521\EasyHttp\Http;
  4. class Crypt extends BasicLife
  5. {
  6. /**
  7. * 获取小程序登录sessionKey
  8. * @param string $code
  9. * @return array
  10. */
  11. public function getSessionKey(string $code = ""): array
  12. {
  13. $url = "https://developer.toutiao.com/api/apps/v2/jscode2session";
  14. $param = [
  15. "appid" => $this->config['appid'],
  16. "secret" => $this->config['secret'],
  17. "code" => $code
  18. ];
  19. $resp = Http::asJson()->post($url,$param)->array();
  20. if ($resp['err_no'] == 0) {
  21. return $resp['data'];
  22. }
  23. return [];
  24. }
  25. /**
  26. * 查询标签组信息 - 用于支付
  27. * @param int $goods_type
  28. * @return array
  29. */
  30. public function getTagGroupId(int $goods_type): array
  31. {
  32. $url = $this->gateway."api/trade_basic/v1/developer/tag_query/";
  33. $param = [
  34. "goods_type" => $goods_type
  35. ];
  36. $resp = Http::asJson()->withHeaders($this->header)->post($url,$param)->array();
  37. if ($resp['err_no'] == 0) {
  38. return $resp['data'];
  39. }
  40. return [];
  41. }
  42. /**
  43. * 小程序获取手机号码
  44. * @param string $code
  45. * @return string
  46. */
  47. public function getMobile(string $code = ""):string
  48. {
  49. $url = $this->gateway."api/apps/v1/get_phonenumber_info/";
  50. $param = [
  51. "code" => $code
  52. ];
  53. $resp = Http::asJson()->withHeaders($this->header)->post($url,$param)->array();
  54. if ($resp['err_no'] == 0) {
  55. return $resp['data'];
  56. }
  57. return "";
  58. }
  59. }