ProgramOpen3rd.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\easywechat\open3rd;
  12. /**
  13. * Class ProgramWechatLive
  14. * @package crmeb\services\wechatlive
  15. */
  16. class ProgramOpen3rd
  17. {
  18. /**
  19. * @var AccessToken
  20. */
  21. protected $accessToken;
  22. /**
  23. * 预授权码
  24. */
  25. const PRE_AUTH_CODE = 'https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode';
  26. /**
  27. * 获取授权方的帐号基本信息
  28. */
  29. const GET_AUTHORIZER_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info';
  30. /**
  31. * 获取体验真列表
  32. */
  33. const MEMBER_AUTH_LIST = 'https://api.weixin.qq.com/wxa/memberauth';
  34. /**
  35. * 绑定体验者
  36. */
  37. const BIND_MEMBER_AUTH = 'https://api.weixin.qq.com/wxa/bind_tester';
  38. /**
  39. * 解除绑定体验者
  40. */
  41. const UNBIND_MEMBER_AUTH = 'https://api.weixin.qq.com/wxa/unbind_tester';
  42. /**
  43. * 获取代码草稿列表
  44. */
  45. const DRAFT_LIST = 'https://api.weixin.qq.com/wxa/gettemplatedraftlist';
  46. /**
  47. * 将草稿添加到代码模板库
  48. */
  49. const ADD_TO_TEMPLATE = 'https://api.weixin.qq.com/wxa/addtotemplate';
  50. /**
  51. * 获取代码模版列表
  52. */
  53. const TEMPLATE_LIST = 'https://api.weixin.qq.com/wxa/gettemplatelist';
  54. /**
  55. * 删除指定代码模版
  56. */
  57. const DEL_TEMPLATE = 'https://api.weixin.qq.com/wxa/deletetemplate';
  58. /**
  59. * 上传代码
  60. */
  61. const COMMIT = 'https://api.weixin.qq.com/wxa/commit';
  62. /**
  63. * 获取已上传的代码页面列表
  64. */
  65. const GET_PAGE = 'https://api.weixin.qq.com/wxa/get_page';
  66. /**
  67. * 获取体验二维码
  68. */
  69. const GET_QRCODE = 'https://api.weixin.qq.com/wxa/get_qrcode';
  70. /**
  71. * 代码提交审核
  72. */
  73. const SUBMIT_AUDIT = 'https://api.weixin.qq.com/wxa/submit_audit';
  74. /**
  75. * 查询指定版本审核状态
  76. */
  77. const GET_AUDIT_STATUS = 'https://api.weixin.qq.com/wxa/get_auditstatus';
  78. /**
  79. * 查询最近一次提交审核状态
  80. */
  81. const GET_LATEST_AUDIT_STATUS = 'https://api.weixin.qq.com/wxa/get_latest_auditstatus';
  82. /**
  83. * 撤回审核
  84. */
  85. const UNDO_CODE_AUDIT = 'https://api.weixin.qq.com/wxa/undocodeaudit';
  86. /**
  87. * 发布已经通过审核的小程序
  88. */
  89. const RELEASE = 'https://api.weixin.qq.com/wxa/release';
  90. /**
  91. * 分阶段发布
  92. */
  93. const GRAY_RELEASE = 'https://api.weixin.qq.com/wxa/grayrelease';
  94. /**
  95. * 版本回退
  96. */
  97. const REVERT_CODE_RELEASE = 'https://api.weixin.qq.com/wxa/revertcoderelease';
  98. /**
  99. * ProgramOpen3rd constructor.
  100. * @param AccessToken $accessToken
  101. */
  102. public function __construct(AccessToken $accessToken)
  103. {
  104. $this->accessToken = $accessToken;
  105. $this->config = $accessToken->getConfig();
  106. }
  107. /**
  108. * 获取预授权码
  109. * @return array|bool|mixed
  110. */
  111. public function getPreAuthCode()
  112. {
  113. return $this->accessToken->httpRequest(self::PRE_AUTH_CODE, [], false);
  114. }
  115. /**
  116. * 获取授权
  117. * @param $authorization_code
  118. * @return authorizer_appid
  119. */
  120. public function getAuth($authorization_code)
  121. {
  122. return $this->accessToken->getAuthorizationInfo($authorization_code);
  123. }
  124. /**
  125. * 获取授权方帐号基本信息
  126. * @param $authorizer_appid
  127. * @return array|bool|mixed
  128. */
  129. public function getAuthorizerinfo(string $authorizer_appid)
  130. {
  131. return $this->accessToken->httpRequest(self::GET_AUTHORIZER_INFO, ['authorizer_appid' => $authorizer_appid], false);
  132. }
  133. /**
  134. * 获取授权体验者列表
  135. * @return array|bool|mixed
  136. */
  137. public function getMemberAuthList()
  138. {
  139. return $this->accessToken->httpRequest(self::MEMBER_AUTH_LIST, ['action' => 'get_experiencer']);
  140. }
  141. /**
  142. * 绑定体验者
  143. * @param string $wechatid
  144. * @return array|bool|mixed
  145. */
  146. public function bindMemberAuth(string $wechatid)
  147. {
  148. return $this->accessToken->httpRequest(self::BIND_MEMBER_AUTH, ['wechatid' => $wechatid]);
  149. }
  150. /**
  151. * 解除绑定体验者
  152. * @param string $wechatid
  153. * @param string $userstr
  154. * @return array|bool|mixed
  155. */
  156. public function unBindMemberAuth(string $wechatid, string $userstr = '')
  157. {
  158. $data = ['wechatid' => $wechatid];
  159. if ($userstr) $data['userstr'] = $userstr;
  160. return $this->accessToken->httpRequest(self::UNBIND_MEMBER_AUTH, $data);
  161. }
  162. /**
  163. * 获取草稿列表
  164. * @return array|bool|mixed
  165. */
  166. public function getDraftList()
  167. {
  168. return $this->accessToken->httpRequest(self::DRAFT_LIST);
  169. }
  170. /**
  171. * 将草稿添加到代码模版
  172. * @param $draft_id
  173. * @return array|bool|mixed
  174. */
  175. public function addToTemplate($draft_id)
  176. {
  177. return $this->accessToken->httpRequest(self::ADD_TO_TEMPLATE, ['draft_id' => $draft_id]);
  178. }
  179. /**
  180. * 获取代码模版列表
  181. * @return array|bool|mixed
  182. */
  183. public function getTemplateList()
  184. {
  185. return $this->accessToken->httpRequest(self::TEMPLATE_LIST);
  186. }
  187. /**
  188. * 删除指定模版
  189. * @param $template_id
  190. * @return array|bool|mixed
  191. */
  192. public function delTemplate($template_id)
  193. {
  194. return $this->accessToken->httpRequest(self::DEL_TEMPLATE, ['template_id' => $template_id]);
  195. }
  196. /**
  197. * 代码上传
  198. * @param $template_id
  199. * @param string $ext_json
  200. * @param string $user_version
  201. * @param string $user_desc
  202. * @return array|bool|mixed
  203. */
  204. public function commit($template_id, string $ext_json, string $user_version, string $user_desc = '')
  205. {
  206. return $this->accessToken->httpRequest(self::COMMIT, ['template_id' => $template_id, 'ext_json' => $ext_json, 'user_version' => $user_version, 'user_desc' => $user_desc]);
  207. }
  208. /**
  209. * 获取已上传代码列表
  210. * @return array|bool|mixed
  211. */
  212. public function getPage()
  213. {
  214. return $this->accessToken->httpRequest(self::GET_PAGE, []);
  215. }
  216. /**
  217. * 获取体验二维码
  218. * @return array|bool|mixed
  219. */
  220. public function getQrcode($path = '')
  221. {
  222. return $this->accessToken->httpRequest(self::GET_QRCODE, ['path' => $path], true, 'GET');
  223. }
  224. /**
  225. * 提交审核
  226. * @param array $data
  227. * @param data = [
  228. * 'item_list' => [],//审核项列表(选填,至多填写 5 项)
  229. * 'preview_info' => (object)[],//预览信息(小程序页面截图和操作录屏)
  230. * 'version_desc' => '',//小程序版本说明和功能解释
  231. * 'feedback_info' => '',//反馈内容,至多 200 字
  232. * 'feedback_stuff' => '',//用 | 分割的 media_id 列表,至多 5 张图片, 可以通过新增临时素材接口上传而得到
  233. * 'ugc_declare' => (object)[],//用户生成内容场景(UGC)信息安全声明
  234. * ];
  235. * @return array|bool|mixed
  236. */
  237. public function submitAudit($data = [])
  238. {
  239. $base = [
  240. 'item_list' => [],
  241. 'preview_info' => (object)[],
  242. 'version_desc' => '',
  243. 'feedback_info' => '',
  244. 'feedback_stuff' => '',
  245. 'ugc_declare' => (object)[],
  246. ];
  247. $data = array_merge($base, $data);
  248. return $this->accessToken->httpRequest(self::SUBMIT_AUDIT, $data);
  249. }
  250. /**
  251. * 查询指定版本的审核状态
  252. * @param string $auditid
  253. * @return array|bool|mixed
  254. */
  255. public function getAuditStatus(string $auditid)
  256. {
  257. return $this->accessToken->httpRequest(self::GET_AUDIT_STATUS, ['auditid' => $auditid]);
  258. }
  259. /**
  260. * 获取最后一次提交审核状态
  261. * @return array|bool|mixed
  262. */
  263. public function getLatestAuditStatus()
  264. {
  265. return $this->accessToken->httpRequest(self::GET_LATEST_AUDIT_STATUS, [], true, 'GET');
  266. }
  267. /**
  268. * 审核撤回
  269. * @return array|bool|mixed
  270. */
  271. public function undoAudit()
  272. {
  273. return $this->accessToken->httpRequest(self::UNDO_CODE_AUDIT, [], true, 'GET');
  274. }
  275. /**
  276. * 发布已通过审核小程序
  277. * @return array|bool|mixed
  278. */
  279. public function release()
  280. {
  281. return $this->accessToken->httpRequest(self::RELEASE);
  282. }
  283. /**
  284. * 分阶段发布
  285. * @param int $gray_percentage 1-100整数
  286. * @return mixed
  287. */
  288. public function grayRelease(int $gray_percentage)
  289. {
  290. return $this->accessToken->httpRequest(self::GRAY_RELEASE, ['gray_percentage' => $gray_percentage]);
  291. }
  292. /**
  293. * 版本回退
  294. * @return array|bool|mixed
  295. */
  296. public function revertCodeRelease()
  297. {
  298. return $this->accessToken->httpRequest(self::REVERT_CODE_RELEASE, [], true, 'GET');
  299. }
  300. }