Sys.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\api;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class Sys extends Model
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. /**
  16. * 保存数据
  17. * @param $save
  18. */
  19. public function saveSys($save) {
  20. $this->where('id',1)->save($save);
  21. }
  22. /**
  23. * 微信配置信息
  24. * @param type $data
  25. */
  26. public function saveWxConfig($data){
  27. $save=[
  28. "appid" => empty($data["appid"])?"":$data["appid"],
  29. "secret" => empty($data["secret"])?"":$data["secret"],
  30. "mchid" => empty($data["mchid"])?"":$data["mchid"],
  31. "apiv2key" => empty($data["apiv2key"])?"":$data["apiv2key"],
  32. "apiclient_key" => empty($data["apiclient_key"])?"":$data["apiclient_key"],
  33. "apiclient_cert" => empty($data["apiclient_cert"])?"":$data["apiclient_cert"],
  34. "notify_url" => empty($data["notify_url"])?"":$data["notify_url"],
  35. ];
  36. $this->where("id",1)->update(["wxconfig"=> serialize($save)]);
  37. }
  38. /**
  39. * 分享配置信息
  40. * @param type $data
  41. */
  42. public function saveShareConfig($data){
  43. $save=[
  44. "img" => empty($data["img"]) ?"":$data["img"],
  45. "title" => empty($data["title"])?"":$data["title"],
  46. "query" => empty($data["query"])?"":$data["query"],
  47. "content" => empty($data["content"])?"":$data["content"],
  48. ];
  49. $this->where("id",1)->update(["shareconfig"=> serialize($save)]);
  50. }
  51. /**
  52. * 获取配置详情
  53. * @return type
  54. */
  55. public function getDataInfo($code=""){
  56. $sys = $this->where("id", 1)->find();
  57. //微信配置
  58. $wxconfig=[
  59. "appid"=>"",
  60. "secret"=>"",
  61. "mchid"=>"",
  62. "apiv2key"=>"",
  63. "apiclient_key"=>"",
  64. "apiclient_cert"=>"",
  65. "notify_url"=>""
  66. ];
  67. if(!empty($sys->wxconfig)){
  68. $wxconfig = unserialize($sys->wxconfig);
  69. }
  70. //分享配置
  71. $shareconfig=[
  72. "img"=>"",
  73. "title"=>"",
  74. "query"=>"",
  75. "content"=>"",
  76. ];
  77. if(!empty($sys->shareconfig)){
  78. $shareconfig = unserialize($sys->shareconfig);
  79. }
  80. if($code=="weixin"){
  81. return $wxconfig;
  82. }
  83. if($code=="share"){
  84. return $shareconfig;
  85. }
  86. $data = $sys->toArray();
  87. $data["shareconfig"] = $shareconfig;
  88. $data["wxconfig"] = $wxconfig;
  89. return $data;
  90. }
  91. /**
  92. * 获取微信配置
  93. * @return bool
  94. */
  95. public function getWeixinConfig(){
  96. $data = $this->getDataInfo("weixin");
  97. foreach($data as $k=>$v){
  98. if(empty($v)){
  99. return false;
  100. }
  101. }
  102. $return=[
  103. "APPID" => $data["appid"],
  104. "APPSECRET" => $data["secret"],
  105. "MCHID" => $data["mchid"],
  106. "ApiV2Key" => $data["apiv2key"],
  107. "ApiclientKey" => "file://".app()->getRootPath()."/".trim($data["apiclient_key"],"/"),
  108. "ApiclientCert" => "file://".app()->getRootPath()."/".trim($data["apiclient_cert"],"/"),
  109. "NOTIFY_URL" => $data["notify_url"],
  110. ];
  111. return $return;
  112. }
  113. }