Service.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addon\weapp\model;
  3. use app\model\BaseModel;
  4. class Service extends BaseModel
  5. {
  6. private $url = "https://www.niushop.com.cn";
  7. private $cert;
  8. public function __construct()
  9. {
  10. if (file_exists('cert.key')) {
  11. $this->cert = file_get_contents('cert.key');
  12. }
  13. }
  14. /**
  15. * 获取已经购买的小程序
  16. */
  17. public function getPurchasedApplet()
  18. {
  19. $url = $this->url . "/auth/Applet/getMemberAppletList";
  20. $data = [
  21. 'cert' => $this->cert
  22. ];
  23. $res = $this->doPost($url, $data);
  24. return json_decode($res, true);
  25. }
  26. /**
  27. * 获取小程序版本列表
  28. * @param unknown $mark
  29. */
  30. public function getAppletVersionList($mark)
  31. {
  32. $url = $this->url . "/auth/Applet/getAppletVersionList";
  33. $data = [
  34. 'cert' => $this->cert,
  35. 'applet_module_mark' => $mark
  36. ];
  37. $res = $this->doPost($url, $data);
  38. return json_decode($res, true);
  39. }
  40. /**
  41. * 获取小程序包数据
  42. * @param unknown $params
  43. */
  44. public function getAppletVersionUpgradeInfo($params)
  45. {
  46. $url = $this->url . "/auth/Applet/getAppletVersionUpgradeInfo";
  47. $data = [
  48. 'cert' => $this->cert,
  49. 'applet_module_mark' => $params['mark'],
  50. 'last_version_release' => $params['release'],
  51. 'type' => $params['type']
  52. ];
  53. $res = $this->doPost($url, $data);
  54. return json_decode($res, true);
  55. }
  56. /**
  57. * 小程序下载
  58. * @param unknown $token
  59. */
  60. public function download($token)
  61. {
  62. $url = $this->url . "/auth/Applet/download?token=" . $token;
  63. return $url;
  64. }
  65. /**
  66. * post 服务器请求
  67. */
  68. private function doPost($post_url, $post_data)
  69. {
  70. $ch = curl_init();
  71. curl_setopt($ch, CURLOPT_URL, $post_url);
  72. curl_setopt($ch, CURLOPT_HEADER, 0);
  73. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  74. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  75. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  76. if ($post_data != '' && !empty($post_data)) {
  77. curl_setopt($ch, CURLOPT_POST, 1);
  78. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  79. }
  80. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  81. $result = curl_exec($ch);
  82. curl_close($ch);
  83. return $result;
  84. }
  85. }