WechatThirdAuthAndIcpForm.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\models;
  8. use app\models\Option;
  9. use app\models\Store;
  10. use app\models\StoreMini;
  11. use app\models\StoreMiniAuth;
  12. use app\models\StoreMiniAuthIcp;
  13. use app\models\StoreMiniIcp;
  14. use app\utils\CurlHelper;
  15. use app\utils\QrCode;
  16. use app\utils\Wechat\WechatMini;
  17. use EasyWeChat\BasicService\Media\Client;
  18. use EasyWeChat\Kernel\BaseClient;
  19. use yii\base\Model;
  20. use yii\helpers\ArrayHelper;
  21. class WechatThirdAuthAndIcpForm extends Model
  22. {
  23. public $data;
  24. public $baseClient;
  25. public $mini_id; //小程序id
  26. public $store_id;
  27. public $app;
  28. public function rules()
  29. {
  30. return [
  31. [['mini_id', 'store_id'], 'integer'],
  32. [['taskid', 'name', 'email', 'invoice_id', 'desc', 'enterprise_phone', 'enterprise_address', 'bank_name',
  33. 'bank_account', 'mailing_address', 'address', 'phone', 'province', 'city', 'district', 'invoice_title',
  34. 'qualification', 'qualification_other', 'account_name', 'account_supplemental', 'third_party_phone', 'service_appid'
  35. ], 'string'],
  36. [['data'], 'safe']
  37. ];
  38. }
  39. public function __construct($config = [])
  40. {
  41. //new BaseClient($app)->httpPostJson(); 访问链接
  42. //new Client($app); 上传文件
  43. parent::__construct($config);
  44. $this->store_id = $config['store_id'];
  45. $this->mini_id = $config['mini_id'];
  46. $this->app = (new WechatMini())::getWechatConfig($config['store_id'], $config['mini_id']);
  47. }
  48. // 提交申请
  49. public function applyAuthAndIcp() {
  50. // $t = \Yii::$app->db->beginTransaction();
  51. try {
  52. $app = $this->app;
  53. if (!$app) {
  54. throw new \Exception('小程序信息未找到');
  55. }
  56. $this->baseClient = $baseClient = new BaseClient($app);
  57. $mini = StoreMini::findOne($this->mini_id);
  58. if (!$mini) {
  59. throw new \Exception('小程序信息查询失败');
  60. }
  61. $store = Store::findOne($this->store_id);
  62. if (!$store) {
  63. throw new \Exception('商城信息查询失败');
  64. }
  65. if (is_string($this->data)) {
  66. $this->data = json_decode($this->data, true);
  67. }
  68. $data = $this->data ?: [
  69. 'auth_data' => [
  70. 'contact_info' => [
  71. 'name' => '',
  72. 'email' =>''
  73. ],
  74. 'invoice_info' => [
  75. 'invoice_type' => 2,
  76. 'electronic' => [
  77. 'id' => '',
  78. 'desc' => ''
  79. ],
  80. 'vat' => [
  81. 'enterprise_phone' => '',
  82. 'id' => '',
  83. 'enterprise_address' => '',
  84. 'bank_name' => '',
  85. 'bank_account' => '',
  86. 'desc' => '',
  87. ],
  88. ],
  89. 'customer_type' => 1,
  90. 'pay_type' => StoreMiniAuth::PAY_TYPE_SELF,
  91. // 'taskid' => '',
  92. 'qualification_other' => [// TODO 图片处理 ['media_id' => '', 'url' => ''] ['微信所需media_id' => '', '前端图片显示地址' => '']
  93. ''
  94. ],
  95. 'account_name' => $mini->mini_nickname,
  96. 'account_name_type' => 1,
  97. 'account_supplemental' => [// TODO 图片处理 ['media_id' => '', 'url' => ''] ['微信所需media_id' => '', '前端图片显示地址' => '']
  98. ''
  99. ],
  100. 'third_party_phone' => Option::get("platform_phone", 0, 'saas')['value'],
  101. 'service_appid' => Option::get("platform_wechat_fuwu_appid", 0, 'saas')['value']
  102. ],
  103. 'icp_subject' => [
  104. 'base_info' => [
  105. 'type' => '',
  106. 'name' => '',
  107. 'province' => '',
  108. 'city' => '',
  109. 'district' => '',
  110. 'address' => '',
  111. 'comment' => ''
  112. ],
  113. 'organize_info' => [
  114. 'certificate_type' => '',
  115. 'certificate_number' => '',
  116. 'certificate_address' => '',
  117. 'certificate_photo' => '',
  118. ],
  119. 'principal_info' => [
  120. 'name' => '',
  121. 'mobile' => '',
  122. 'email' => '',
  123. 'emergency_contact' => '',
  124. 'certificate_type' => '',
  125. 'certificate_number' => '',
  126. 'certificate_validity_date_start' => '',
  127. 'certificate_validity_date_end' => '',
  128. 'certificate_photo_front' => '',
  129. 'certificate_photo_back' => '',
  130. 'authorization_letter' => '',
  131. 'verify_task_id' => '',
  132. ],
  133. 'legal_person_info' => [
  134. 'name' => '',
  135. 'certificate_number' => ''
  136. ]
  137. ],
  138. 'icp_applets' => [
  139. 'base_info' => [
  140. 'service_content_types' => '',
  141. 'nrlx_details' => [
  142. [
  143. 'type' => 24,
  144. 'code' => '',
  145. 'media' => ''
  146. ]
  147. ],
  148. 'comment' => ''
  149. ],
  150. 'principal_info' => [
  151. 'name' => '',
  152. 'mobile' => '',
  153. 'email' => '',
  154. 'emergency_contact' => '',
  155. 'certificate_type' => '',
  156. 'certificate_number' => '',
  157. 'certificate_validity_date_start' => '',
  158. 'certificate_validity_date_end' => '',
  159. 'certificate_photo_front' => '',
  160. 'certificate_photo_back' => '',
  161. 'authorization_letter' => '',
  162. 'verify_task_id' => '',
  163. ]
  164. ],
  165. 'icp_materials' => [
  166. 'commitment_letter' => [
  167. ''
  168. ],
  169. 'business_name_change_letter' => [
  170. ''
  171. ],
  172. 'party_building_confirmation_letter' => [
  173. ''
  174. ],
  175. 'promise_video' => [
  176. ''
  177. ],
  178. 'authenticity_responsibility_letter' => [
  179. ''
  180. ],
  181. 'authenticity_commitment_letter' => [
  182. ''
  183. ],
  184. 'website_construction_proposal' => [
  185. ''
  186. ],
  187. 'subject_other_materials' => [
  188. ''
  189. ],
  190. 'applets_other_materials' => [
  191. ''
  192. ],
  193. 'holding_certificate_photo' => [
  194. ''
  195. ],
  196. ]
  197. ];
  198. if (isset($data['auth_data']['third_party_phone']) && empty($data['auth_data']['third_party_phone'])) {
  199. $data['auth_data']['third_party_phone'] = Option::get("platform_phone", 0, 'saas')['value'];
  200. } else {
  201. $data['auth_data'] = array_merge($data['auth_data'], ['third_party_phone' => Option::get("platform_phone", 0, 'saas')['value']]);
  202. }
  203. if (intval($data['auth_data']['pay_type']) === StoreMiniAuth::PAY_TYPE_SERVICE) {
  204. if ($store->mini_auth_num <= 0) {
  205. throw new \Exception('当前商城认证代缴次数不足,请联系平台管理员');
  206. }
  207. if (isset($data['auth_data']['service_appid']) && empty($data['auth_data']['service_appid'])) {
  208. $data['auth_data']['service_appid'] = Option::get('platform_wechat_fuwu_appid', 0, 'saas', '')['value'];
  209. } else {
  210. $data['auth_data'] = array_merge($data['auth_data'], ['service_appid' => Option::get('platform_wechat_fuwu_appid', 0, 'saas', '')['value']]);
  211. }
  212. }
  213. //处理ocr_data是json字符 且前端一直json不解密问题
  214. $data['ocr_data'] = $this->handleJsonData($data['ocr_data']);
  215. $mini_auth_icp = StoreMiniAuthIcp::findOne(['store_id' => $this->store_id, 'mini_id' => $this->mini_id]) ?: new StoreMiniAuthIcp();
  216. $mini_auth_icp->store_id = $this->store_id;
  217. $mini_auth_icp->mini_id = $this->mini_id;
  218. $mini_auth_icp->data = json_encode($data, JSON_UNESCAPED_UNICODE);
  219. $mini_auth_icp->ocr_data = json_encode($data['ocr_data'], JSON_UNESCAPED_UNICODE);
  220. if (!$mini_auth_icp->save()) {
  221. throw new \Exception(implode(';', array_values($mini_auth_icp->firstErrors)));
  222. }
  223. unset($data['ocr_data']);
  224. $data['icp_subject']['principal_info']['certificate_validity_date_start'] = date('Ymd', strtotime($data['icp_subject']['principal_info']['certificate_validity_date_start']));
  225. if ($data['icp_subject']['principal_info']['certificate_validity_date_end'] !== '长期') {
  226. $data['icp_subject']['principal_info']['certificate_validity_date_end'] = date('Ymd', strtotime($data['icp_subject']['principal_info']['certificate_validity_date_end']));
  227. }
  228. $data['icp_applets']['principal_info']['certificate_validity_date_start'] = date('Ymd', strtotime($data['icp_applets']['principal_info']['certificate_validity_date_start']));
  229. if ($data['icp_applets']['principal_info']['certificate_validity_date_end'] !== '长期') {
  230. $data['icp_applets']['principal_info']['certificate_validity_date_end'] = date('Ymd', strtotime($data['icp_applets']['principal_info']['certificate_validity_date_end']));
  231. }
  232. if (!in_array($data['auth_data']['customer_type'], [1, 12])) {
  233. throw new \Exception('身份类型枚举值错误');
  234. }
  235. // 支付方式
  236. if (!in_array($data['auth_data']['pay_type'], [StoreMiniAuth::PAY_TYPE_SERVICE, StoreMiniAuth::PAY_TYPE_SELF])) {
  237. throw new \Exception('支付方式枚举值错误');
  238. }
  239. if (intval($data['auth_data']['pay_type']) === StoreMiniAuth::PAY_TYPE_SERVICE) {//支付方式 1:消耗服务商预购包
  240. //发票信息,如果是服务商代缴模式,不需要改参数
  241. // unset($data['auth_data']['invoice_info']);
  242. $data['auth_data']['invoice_info']['invoice_type'] = 1;
  243. if (empty($data['auth_data']['service_appid'])) {
  244. throw new \Exception('请选择服务市场appid');
  245. }
  246. } else {
  247. // 发票类型
  248. if (!in_array($data['auth_data']['invoice_info']['invoice_type'], [1, 2, 4])) {
  249. throw new \Exception('发票类型枚举值错误');
  250. }
  251. //不开发票
  252. if (intval($data['auth_data']['invoice_info']['invoice_type']) === 1) {
  253. unset($data['auth_data']['invoice_info']['vat'], $data['auth_data']['invoice_info']['electronic']);
  254. }
  255. // 电子发票
  256. if (intval($data['auth_data']['invoice_info']['invoice_type']) === 2) {
  257. // 未填写电子发票开票信息
  258. if (empty($data['auth_data']['invoice_info']['electronic'])) {
  259. throw new \Exception('未填写电子发票开票信息');
  260. }
  261. // 未填写电子发票纳税识别号
  262. if (empty($data['auth_data']['invoice_info']['electronic']['id'])) {
  263. throw new \Exception('未填写电子发票纳税识别号');
  264. }
  265. unset($data['auth_data']['invoice_info']['vat']);
  266. }
  267. // 增值税专票
  268. if (intval($data['auth_data']['invoice_info']['invoice_type']) === 4) {
  269. // 未填写电子发票开票信息
  270. if (empty($data['auth_data']['invoice_info']['vat'])) {
  271. throw new \Exception('未填写增值税专票开票信息');
  272. }
  273. // 未填写企业电话
  274. if (empty($data['auth_data']['invoice_info']['vat']['enterprise_phone'])) {
  275. throw new \Exception('未填写企业电话');
  276. }
  277. // 未填写电子发票纳税识别号
  278. if (empty($data['auth_data']['invoice_info']['vat']['id'])) {
  279. throw new \Exception('未填写增值税专票纳税识别号');
  280. }
  281. // 未填写企业注册地址
  282. if (empty($data['auth_data']['invoice_info']['vat']['enterprise_address'])) {
  283. throw new \Exception('未填写企业注册地址');
  284. }
  285. // 未填写企业开户银行
  286. if (empty($data['auth_data']['invoice_info']['vat']['bank_name'])) {
  287. throw new \Exception('未填写企业开户银行');
  288. }
  289. // 未填写企业银行账号
  290. if (empty($data['auth_data']['invoice_info']['vat']['bank_account'])) {
  291. throw new \Exception('未填写企业银行账号');
  292. }
  293. unset($data['auth_data']['invoice_info']['electronic']);
  294. }
  295. }
  296. //组装微信所需数据
  297. //名称命中关键词-补充材料
  298. if ($data['auth_data']['account_supplemental']) {
  299. $account_supplemental = [];
  300. foreach ($data['auth_data']['account_supplemental'] as $account_supplemental_item) {
  301. $account_supplemental[] = $account_supplemental_item['media_id'];
  302. }
  303. if (!empty($account_supplemental)) {
  304. $data['auth_data']['account_supplemental'] = $account_supplemental;
  305. }
  306. }
  307. //主体资质其他证明材料,最多上传10张图片
  308. if ($data['auth_data']['qualification_other']) {
  309. $qualification_other = [];
  310. foreach ($data['auth_data']['qualification_other'] as $qualification_other_item) {
  311. $qualification_other[] = $qualification_other_item['media_id'];
  312. }
  313. if (!empty($qualification_other)) {
  314. $data['auth_data']['qualification_other'] = $qualification_other;
  315. }
  316. }
  317. if (count($data['auth_data']['qualification_other']) > 10) {
  318. throw new \Exception('主体资质其他证明材料,最多上传10张图片');
  319. }
  320. // 小程序账号名称
  321. if (empty($data['auth_data']['account_name'])) {
  322. throw new \Exception('需要填写小程序账号名称');
  323. }
  324. // 小程序账号名称命名类型
  325. if (!in_array($data['auth_data']['account_name_type'], [1, 2])) {
  326. throw new \Exception('小程序账号名称命名类型枚举值错误');
  327. }
  328. // 第三方联系电话
  329. if (empty($data['auth_data']['third_party_phone'])) {
  330. throw new \Exception('需要填写第三方联系电话');
  331. }
  332. //备案资料验证
  333. //主体额外信息 主体证件照片 media_id
  334. $certificate_photo = $data['icp_subject']['organize_info']['certificate_photo'];
  335. if ($certificate_photo) {
  336. $data['icp_subject']['organize_info']['certificate_photo'] = $certificate_photo['media_id'];
  337. }
  338. //主体负责人信息-负责人证件正面照片
  339. $certificate_photo_front = $data['icp_subject']['principal_info']['certificate_photo_front'];
  340. if ($certificate_photo_front) {
  341. $data['icp_subject']['principal_info']['certificate_photo_front'] = $certificate_photo_front['media_id'];
  342. }
  343. //主体负责人信息-负责人证件背面照片
  344. $certificate_photo_back = $data['icp_subject']['principal_info']['certificate_photo_back'];
  345. if ($certificate_photo_back) {
  346. $data['icp_subject']['principal_info']['certificate_photo_back'] = $certificate_photo_back['media_id'];
  347. }
  348. //主体负责人信息-授权书
  349. $authorization_letter = $data['icp_subject']['principal_info']['authorization_letter'];
  350. if ($authorization_letter) {
  351. $data['icp_subject']['principal_info']['authorization_letter'] = $authorization_letter['media_id'];
  352. }
  353. //扫脸认证任务id(扫脸认证接口返回的task_id)
  354. $data['icp_subject']['principal_info']['verify_task_id'] = $mini_auth_icp->task_id;
  355. //前置审批项
  356. if ($data['icp_applets']['base_info']['nrlx_details']) {
  357. foreach ($data['icp_applets']['base_info']['nrlx_details'] as $nrlx_index => $nrlx_item) {
  358. if (intval($nrlx_item['type']) === 24) {//以上都不涉及
  359. $data['icp_applets']['base_info']['nrlx_details'][$nrlx_index] = [
  360. 'type' => 24
  361. ];
  362. } else {
  363. $data['icp_applets']['base_info']['nrlx_details'][$nrlx_index]['media'] = $nrlx_item['media_id'];
  364. }
  365. }
  366. } else {
  367. $data['icp_applets']['base_info']['nrlx_details'] = [
  368. [
  369. 'type' => 24
  370. ]
  371. ];
  372. }
  373. if (empty($data['icp_applets']['base_info']['comment'])) {
  374. throw new \Exception('请具体描述小程序实际经营内容、主要服务内容,该信息为主管部门审核重要依据,备注内容字数限制20-200字,请认真填写。(特殊备注要求请查看注意事项)');
  375. }
  376. //微信小程序负责人信息-负责人证件正面照片
  377. $certificate_photo_front = $data['icp_applets']['principal_info']['certificate_photo_front'];
  378. if ($certificate_photo_front) {
  379. $data['icp_applets']['principal_info']['certificate_photo_front'] = $certificate_photo_front['media_id'];
  380. }
  381. //微信小程序负责人信息-负责人证件背面照片
  382. $certificate_photo_back = $data['icp_applets']['principal_info']['certificate_photo_back'];
  383. if ($certificate_photo_back) {
  384. $data['icp_applets']['principal_info']['certificate_photo_back'] = $certificate_photo_back['media_id'];
  385. }
  386. //主体负责人信息-授权书
  387. $authorization_letter = $data['icp_applets']['principal_info']['authorization_letter'];
  388. if ($authorization_letter) {
  389. $data['icp_applets']['principal_info']['authorization_letter'] = $authorization_letter['media_id'];
  390. }
  391. //扫脸认证任务id(扫脸认证接口返回的task_id)
  392. $data['icp_applets']['principal_info']['verify_task_id'] = $mini_auth_icp->task_id;
  393. $wechatMiniIcpForm = new WechatMiniIcpForm();
  394. //其他备案媒体材料-互联网信息服务承诺书 最大数量1
  395. $commitment_letter_ = $data['icp_materials']['commitment_letter'];
  396. if ($commitment_letter_) {
  397. $data['icp_materials']['commitment_letter'] = $wechatMiniIcpForm->arrayChange($commitment_letter_);
  398. }
  399. //其他备案媒体材料-主体更名函 media_id(非个人类型,且发生过更名时需要上传) 最大数量1
  400. $business_name_change_letter_ = $data['icp_materials']['business_name_change_letter'];
  401. if ($business_name_change_letter_) {
  402. $data['icp_materials']['business_name_change_letter'] = $wechatMiniIcpForm->arrayChange($business_name_change_letter_);
  403. }
  404. //其他备案媒体材料-党建确认函 最大数量1
  405. $party_building_confirmation_letter_ = $data['icp_materials']['party_building_confirmation_letter'];
  406. if ($party_building_confirmation_letter_) {
  407. $data['icp_materials']['party_building_confirmation_letter'] = $wechatMiniIcpForm->arrayChange($party_building_confirmation_letter_);
  408. }
  409. //其他备案媒体材料-承诺视频 最大数量1
  410. $promise_video_ = $data['icp_materials']['promise_video'];
  411. if ($promise_video_) {
  412. $data['icp_materials']['promise_video'] = $wechatMiniIcpForm->arrayChange($promise_video_);
  413. }
  414. //其他备案媒体材料-党建确认函 最大数量1
  415. $authenticity_responsibility_letter_ = $data['icp_materials']['authenticity_responsibility_letter'];
  416. if ($authenticity_responsibility_letter_) {
  417. $data['icp_materials']['authenticity_responsibility_letter'] =$wechatMiniIcpForm->arrayChange($authenticity_responsibility_letter_);
  418. }
  419. //其他备案媒体材料-小程序备案信息真实性承诺书 最大数量1
  420. $authenticity_commitment_letter_ = $data['icp_materials']['authenticity_commitment_letter'];
  421. if ($authenticity_commitment_letter_) {
  422. $data['icp_materials']['authenticity_commitment_letter'] = $wechatMiniIcpForm->arrayChange($authenticity_commitment_letter_);
  423. }
  424. //其他备案媒体材料-小程序建设方案书 最大数量1
  425. $website_construction_proposal_ = $data['icp_materials']['website_construction_proposal'];
  426. if ($website_construction_proposal_) {
  427. $data['icp_materials']['website_construction_proposal'] = $wechatMiniIcpForm->arrayChange($website_construction_proposal_);
  428. }
  429. //其他备案媒体材料-主体其它附件 最大数量10
  430. $subject_other_materials_ = $data['icp_materials']['subject_other_materials'];
  431. if ($subject_other_materials_) {
  432. $data['icp_materials']['subject_other_materials'] = $wechatMiniIcpForm->arrayChange($subject_other_materials_);
  433. }
  434. //其他备案媒体材料-小程序其它附件 最大数量10
  435. $applets_other_materials_ = $data['icp_materials']['applets_other_materials'];
  436. if ($applets_other_materials_) {
  437. $data['icp_materials']['applets_other_materials'] = $wechatMiniIcpForm->arrayChange($applets_other_materials_);
  438. }
  439. //其他备案媒体材料-手持证件照 最大数量1
  440. $holding_certificate_photo_ = $data['icp_materials']['holding_certificate_photo'];
  441. if ($holding_certificate_photo_) {
  442. $data['icp_materials']['holding_certificate_photo'] = $wechatMiniIcpForm->arrayChange($holding_certificate_photo_);
  443. }
  444. if (isset($data['mini_id'])) {
  445. unset($data['mini_id']);
  446. }
  447. $result = $baseClient->httpPostJson('wxa/sec/submit_auth_and_icp', $data);
  448. debug_log(['store_id' => $this->store_id, 'mini_id' => $this->mini_id, 'result' => $result], 'wxa_auth_icp.log');
  449. if (empty($result['errcode']) && !empty($result)) {
  450. if ($result['procedure_id']) {
  451. $mini_auth_icp->procedure_id = $result['procedure_id'];
  452. }
  453. if ($result['pay_url']) {
  454. $mini_auth_icp->pay_url = $result['pay_url'];
  455. }
  456. $url = $result['pay_url'];
  457. if ($url) {
  458. $pic_url = $this->setPicUrl($url, $mini_auth_icp->id);
  459. $mini_auth_icp->pay_qrcode_url = $pic_url;
  460. }
  461. if (intval($data['auth_data']['pay_type']) === StoreMiniAuth::PAY_TYPE_SERVICE) {
  462. $mini_auth_icp->is_use_service = 1;
  463. }
  464. if (!$mini_auth_icp->save()) {
  465. throw new \Exception(implode(';', array_values($mini_auth_icp->firstErrors)));
  466. }
  467. // $t->commit();
  468. return [
  469. 'code' => 0,
  470. 'msg' => "成功",
  471. 'data' => [
  472. 'auth_url' => $result['auth_url']
  473. ]
  474. ];
  475. } else {
  476. if ($result['hints']) {
  477. $mini_auth_icp->hints = json_encode($result['hints'], JSON_UNESCAPED_UNICODE);
  478. if (!$mini_auth_icp->save()) {
  479. throw new \Exception(implode(';', array_values($mini_auth_icp->firstErrors)));
  480. }
  481. }
  482. if (!empty($result['hints'])) {
  483. $result['errmsg'] = implode(';', array_column($result['hints'], 'errmsg'));
  484. }
  485. if (strpos($result['errmsg'], 'cURL error 28') !== false) {
  486. $this->queryAuthAndIcp();
  487. $storeMiniAuthIcp = StoreMiniAuthIcp::findOne(['mini_id' => $this->mini_id]);
  488. if (!in_array($storeMiniAuthIcp->face_is_finish, [
  489. StoreMiniAuthIcp::PROCEDURE_STATUS_NOT_START,
  490. StoreMiniAuthIcp::PROCEDURE_STATUS_AUTH_AUDIT_REJECT,
  491. StoreMiniAuthIcp::PROCEDURE_STATUS_AUTH_AUDIT_FINAL_FAIL,
  492. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_AUDIT_FAIL,
  493. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_PLATFORM_AUDIT_REJECT,
  494. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_GOVERNMENT_AUDIT_REJECT
  495. ])) {
  496. return [
  497. 'code' => 0,
  498. 'msg' => "成功",
  499. 'data' => [
  500. 'auth_url' => ''
  501. ]
  502. ];
  503. }
  504. $message = intval($storeMiniAuthIcp->face_is_finish) === StoreMiniAuthIcp::FACE_FINISH ?
  505. StoreMiniAuthIcp::PROCEDURE_STATUS_NAME[intval($storeMiniAuthIcp->procedure_status)] :
  506. StoreMiniAuthIcp::FACE_STATUS_NAME[intval($storeMiniAuthIcp->face_status)];
  507. throw new \Exception('微信服务器返回信息异常 请尝试返回上一页刷新状态或重新提交,当前状态为:' . $message);
  508. }
  509. throw new \Exception($result['errmsg'], $result['errcode']);
  510. }
  511. } catch (\Exception $e) {
  512. // $t->rollBack();
  513. return [
  514. 'code' => $e->getCode() ?: 1,
  515. 'msg' => $e->getMessage()
  516. ];
  517. }
  518. }
  519. public function handleJsonData($data) {
  520. if (is_string($data)) {
  521. $data = json_decode($data, true);
  522. if (is_string($data)) {
  523. return $this->handleJsonData($data);
  524. }
  525. }
  526. return $data;
  527. }
  528. //查询认证以及备案流程
  529. public function queryAuthAndIcp() {
  530. try {
  531. //请求微信接口
  532. $app = $this->app;
  533. if (!$app) {
  534. throw new \Exception('获取小程序信息失败');
  535. }
  536. $mini_id = $this->mini_id;
  537. $store_mini_auth_icp = StoreMiniAuthIcp::findOne(['mini_id' => $mini_id, 'is_delete' => 0]);
  538. $client = new BaseClient($app);
  539. $data = [
  540. 'procedure_id' => $store_mini_auth_icp->procedure_id,
  541. ];
  542. $result = $client->httpPostJson('wxa/sec/query_auth_and_icp', $data);
  543. //返回微信信息
  544. if ($result['errcode']) {
  545. throw new \Exception($result['errmsg'], $result['errcode']);
  546. }
  547. $store_mini_auth_icp->procedure_status = $result['procedure_status'];
  548. $store_mini_auth_icp->orderid = $result['orderid'];
  549. $store_mini_auth_icp->refill_reason = $result['refill_reason'];
  550. $store_mini_auth_icp->fail_reason = $result['fail_reason'];
  551. if ($result['icp_audit']) {
  552. $store_mini_auth_icp->icp_audit = json_encode($result['icp_audit'], JSON_UNESCAPED_UNICODE);
  553. if ($result['icp_audit']['hints']) {
  554. $store_mini_auth_icp->hints = json_encode($result['icp_audit']['hints'], JSON_UNESCAPED_UNICODE);
  555. }
  556. $store_mini_auth_icp->sms_verify_status = $result['icp_audit']['sms_verify_status'];
  557. }
  558. if (!$store_mini_auth_icp->save()) {
  559. throw new \Exception(implode(';', array_values($store_mini_auth_icp->firstErrors)));
  560. }
  561. return [
  562. 'code' => 0,
  563. 'msg' => "成功"
  564. ];
  565. } catch (\Exception $e) {
  566. return [
  567. 'code' => 1,
  568. 'msg' => $e->getMessage()
  569. ];
  570. }
  571. }
  572. //任务流程状态枚举:15=等待支付认证审核费用;16=认证审核费用支付成功;17=认证审核中;18=认证审核驳回;19=认证审核通过;20=认证审核最终失败(不能再修改);21=创建备案审核单失败;22=备案平台审核中;23=备案平台审核驳回;24=备案管局审核中;25=管局审核驳回;26=认证及备案完成;
  573. // 获取信息
  574. public function getApplyData() {
  575. try {
  576. $mini = StoreMini::findOne($this->mini_id);
  577. if (!$mini) {
  578. throw new \Exception('小程序信息查询失败');
  579. }
  580. $data = [
  581. 'auth_data' => [
  582. 'contact_info' => [
  583. 'name' => '',
  584. 'email' =>''
  585. ],
  586. 'invoice_info' => [
  587. 'invoice_type' => 2,
  588. 'electronic' => [
  589. 'id' => '',
  590. 'desc' => ''
  591. ],
  592. 'vat' => [
  593. 'enterprise_phone' => '',
  594. 'id' => '',
  595. 'enterprise_address' => '',
  596. 'bank_name' => '',
  597. 'bank_account' => '',
  598. 'desc' => '',
  599. ],
  600. // 'invoice_title' => '',
  601. ],
  602. 'customer_type' => 1,
  603. 'pay_type' => StoreMiniAuth::PAY_TYPE_SELF,
  604. // 'taskid' => '',
  605. 'qualification_other' => [// TODO 图片处理 ['media_id' => '', 'url' => ''] ['微信所需media_id' => '', '前端图片显示地址' => '']
  606. ],
  607. 'account_name' => $mini->mini_nickname,
  608. 'account_name_type' => 1,
  609. 'account_supplemental' => [// TODO 图片处理 ['media_id' => '', 'url' => ''] ['微信所需media_id' => '', '前端图片显示地址' => '']
  610. ],
  611. 'third_party_phone' => Option::get("platform_phone", 0, 'saas')['value'],
  612. 'service_appid' => Option::get("platform_wechat_fuwu_appid", 0, 'saas')['value']
  613. ],
  614. 'icp_subject' => [
  615. 'base_info' => [
  616. 'type' => '',
  617. 'name' => '',
  618. 'province' => '',
  619. 'city' => '',
  620. 'district' => '',
  621. 'address' => '',
  622. 'comment' => ''
  623. ],
  624. 'organize_info' => [
  625. 'certificate_type' => '',
  626. 'certificate_number' => '',
  627. 'certificate_address' => '',
  628. 'certificate_photo' => [
  629. 'media_id' => '',
  630. 'url' => ''
  631. ],
  632. ],
  633. 'principal_info' => [
  634. 'name' => '',
  635. 'mobile' => '',
  636. 'email' => '',
  637. 'emergency_contact' => '',
  638. 'certificate_type' => '',
  639. 'certificate_number' => '',
  640. 'certificate_validity_date_start' => '',
  641. 'certificate_validity_date_end' => '',
  642. 'certificate_photo_front' => [
  643. 'media_id' => '',
  644. 'url' => ''
  645. ],
  646. 'certificate_photo_back' => [
  647. 'media_id' => '',
  648. 'url' => ''
  649. ],
  650. 'authorization_letter' => [
  651. 'media_id' => '',
  652. 'url' => ''
  653. ],
  654. 'verify_task_id' => '',
  655. ],
  656. 'legal_person_info' => [
  657. 'name' => '',
  658. 'certificate_number' => ''
  659. ]
  660. ],
  661. 'icp_applets' => [
  662. 'base_info' => [
  663. 'service_content_types' => '',
  664. 'nrlx_details' => [
  665. [
  666. 'type' => 24,
  667. 'code' => '',
  668. 'media' => ''
  669. ]
  670. ],
  671. 'comment' => ''
  672. ],
  673. 'principal_info' => [
  674. 'name' => '',
  675. 'mobile' => '',
  676. 'email' => '',
  677. 'emergency_contact' => '',
  678. 'certificate_type' => '',
  679. 'certificate_number' => '',
  680. 'certificate_validity_date_start' => '',
  681. 'certificate_validity_date_end' => '',
  682. 'certificate_photo_front' => [
  683. 'media_id' => '',
  684. 'url' => ''
  685. ],
  686. 'certificate_photo_back' => [
  687. 'media_id' => '',
  688. 'url' => ''
  689. ],
  690. 'authorization_letter' => [
  691. 'media_id' => '',
  692. 'url' => ''
  693. ],
  694. 'verify_task_id' => '',
  695. ]
  696. ],
  697. 'icp_materials' => [
  698. 'commitment_letter' => [
  699. ],
  700. 'business_name_change_letter' => [
  701. ],
  702. 'party_building_confirmation_letter' => [
  703. ],
  704. 'promise_video' => [
  705. ],
  706. 'authenticity_responsibility_letter' => [
  707. ],
  708. 'authenticity_commitment_letter' => [
  709. ],
  710. 'website_construction_proposal' => [
  711. ],
  712. 'subject_other_materials' => [
  713. ],
  714. 'applets_other_materials' => [
  715. ],
  716. 'holding_certificate_photo' => [
  717. ],
  718. ]
  719. ];
  720. // 查询人脸识别状态 如果已经达到最终态就不再请求接口
  721. //
  722. $ocr_data = [
  723. 'organize_certificate_photo' => '',
  724. 'certificate_photo_front' => '',
  725. 'certificate_photo_back' => '',
  726. ];
  727. $mini_auth_icp = StoreMiniAuthIcp::findOne(['store_id' => $this->store_id, 'mini_id' => $this->mini_id]);
  728. $pic_url = '';
  729. if ($mini_auth_icp) {
  730. // $this->getTaskStatus($mini_auth_icp);
  731. $data = json_decode($mini_auth_icp->data, JSON_UNESCAPED_UNICODE) ?: $data;
  732. //处理ocr_data是json字符 且前端一直json不解密问题
  733. $data['ocr_data'] = $this->handleJsonData($data['ocr_data']);
  734. if (!empty($mini_auth_icp->pay_url)) {
  735. $pic_url = $this->setPicUrl($mini_auth_icp->pay_url, $mini_auth_icp->id);
  736. $mini_auth_icp->pay_qrcode_url = $pic_url;
  737. $mini_auth_icp->save();
  738. }
  739. if (isset($data['mini_id'])) {
  740. $data['mini_id'] = $this->mini_id;
  741. }
  742. $ocr_data = json_decode($mini_auth_icp->ocr_data, true) ?: $ocr_data;
  743. //处理ocr_data是json字符 且前端一直json不解密问题
  744. $ocr_data = $this->handleJsonData($ocr_data);
  745. }
  746. $icp_form = new WechatMiniIcpForm(['store_id' => $this->mini_id, 'mini_id' => $this->mini_id]);
  747. //单位性质
  748. $subject_types = null;
  749. $icpSubjectTypesResult = $icp_form->queryIcpSubjectTypes();
  750. if ($icpSubjectTypesResult['code'] === 0) {
  751. $subject_types = $icpSubjectTypesResult['data']['data'];
  752. }
  753. //区域信息
  754. $district_code = null;
  755. $icpDistrictCodeResult = $icp_form->queryIcpDistrictCode();
  756. if ($icpDistrictCodeResult['code'] === 0) {
  757. $district_code = $icpDistrictCodeResult['data']['data'];
  758. }
  759. //获取证件类型
  760. $certificate_types = null;
  761. $icpCertificateTypesResult = $icp_form->queryIcpCertificateTypes();
  762. if ($icpCertificateTypesResult['code'] === 0) {
  763. $certificate_types = $icpCertificateTypesResult['data']['data'];
  764. }
  765. //获取前置审批项类型
  766. $nrlx_types = null;
  767. $queryIcpNrlxTypesResult = $icp_form->queryIcpNrlxTypes();
  768. if ($queryIcpNrlxTypesResult['code'] === 0) {
  769. $nrlx_types = $queryIcpNrlxTypesResult['data']['data'];
  770. }
  771. //获取小程序服务内容类型
  772. $service_content_types = null;
  773. $icpServiceContentTypesResult = $icp_form->queryIcpServiceContentTypes();
  774. if ($icpServiceContentTypesResult['code'] === 0) {
  775. $service_content_types = $icpServiceContentTypesResult['data']['data'];
  776. }
  777. $is_submit = false;
  778. if (in_array($mini_auth_icp->procedure_status, [
  779. StoreMiniAuthIcp::PROCEDURE_STATUS_NOT_START,
  780. StoreMiniAuthIcp::PROCEDURE_STATUS_AUTH_AUDIT_REJECT,
  781. StoreMiniAuthIcp::PROCEDURE_STATUS_AUTH_AUDIT_FINAL_FAIL,
  782. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_AUDIT_FAIL,
  783. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_PLATFORM_AUDIT_REJECT,
  784. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_GOVERNMENT_AUDIT_REJECT,
  785. ])) {
  786. $is_submit = true;
  787. }
  788. $fail_reason = $mini_auth_icp->fail_reason;
  789. if (in_array($mini_auth_icp->procedure_status, [
  790. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_PLATFORM_AUDIT_REJECT,
  791. StoreMiniAuthIcp::PROCEDURE_STATUS_ICP_GOVERNMENT_AUDIT_REJECT
  792. ])) {
  793. $message = '';
  794. $icp_audit_data = json_decode($mini_auth_icp->icp_audit, true);
  795. foreach ($icp_audit_data['audit_data'] as $icp_audit_item) {
  796. $message .= $icp_audit_item['error'] . "_" . $icp_audit_item['suggest'] . ';';
  797. }
  798. $fail_reason = $message;
  799. }
  800. return [
  801. 'code' => 0,
  802. 'msg' => '获取成功',
  803. 'data' => [
  804. 'data' => $data,
  805. 'pay_url' => $pic_url ?: '',
  806. 'procedure_status' => intval($mini_auth_icp->procedure_status) ?: 0,
  807. 'procedure_status_text' => StoreMiniAuthIcp::PROCEDURE_STATUS_NAME[$mini_auth_icp->procedure_status ?: 0],
  808. 'sms_verify_status' => intval($mini_auth_icp->sms_verify_status) ?: 0,
  809. 'sms_verify_status_text' => StoreMiniAuthIcp::SMS_VERIFY_STATUS_NAME[$mini_auth_icp->sms_verify_status ?: 0],
  810. 'refill_reason' => $mini_auth_icp->refill_reason,
  811. 'fail_reason' => $fail_reason,
  812. // 'is_edit' => $is_edit,
  813. 'subject_types' => $subject_types,
  814. 'district_code' => $district_code,
  815. 'certificate_types' => $certificate_types,
  816. 'nrlx_types' => $nrlx_types,
  817. 'service_content_types' => $service_content_types,
  818. 'is_submit' => $is_submit,
  819. 'ocr_data' => $ocr_data
  820. ]
  821. ];
  822. } catch (\Exception $e) {
  823. return [
  824. 'code' => 1,
  825. 'msg' => $e->getMessage()
  826. ];
  827. }
  828. }
  829. //获取人脸核身任务状态 状态:-1未创建任务;1待核验;2=成功;3=失败;
  830. public function queryIcpVerifyTask() {
  831. try {
  832. //请求微信接口
  833. $app = $this->app;
  834. if (!$app) {
  835. throw new \Exception('获取小程序信息失败');
  836. }
  837. $mini_id = $this->mini_id;
  838. $store_mini_auth_icp = StoreMiniAuthIcp::findOne(['mini_id' => $mini_id, 'is_delete' => 0]);
  839. if (empty($store_mini_auth_icp->task_id)) {
  840. return [
  841. 'code' => 0,
  842. 'msg' => '',
  843. 'data' => [
  844. 'face_status' => -1,//未创建
  845. 'face_status_text' => '等待人脸核身任务创建',
  846. 'face_verify_qrcode_url' => ''
  847. ]
  848. ];
  849. }
  850. if ($store_mini_auth_icp->face_is_finish) {
  851. return [
  852. 'code' => 0,
  853. 'msg' => '',
  854. 'data' => [
  855. 'face_status' => StoreMiniAuthIcp::FACE_STATUS_SUCCESS,
  856. 'face_status_text' => '',
  857. 'face_verify_qrcode_url' => ''
  858. ]
  859. ];
  860. }
  861. $data = [
  862. 'task_id' => $store_mini_auth_icp->task_id,
  863. ];
  864. $client = new BaseClient($app);
  865. $result = $client->httpPostJson('wxa/icp/query_icp_verifytask', $data);
  866. //返回微信信息
  867. if ($result['errcode']) {
  868. throw new \Exception($result['errmsg'], $result['errcode']);
  869. }
  870. $store_mini_auth_icp->face_is_finish = intval($result['is_finish']);
  871. $store_mini_auth_icp->face_status = intval($result['face_status']);
  872. $store_mini_auth_icp->face_along_with_auth_result = intval($result['along_with_auth_result']);
  873. if (!$store_mini_auth_icp->save()) {
  874. throw new \Exception(implode(';', array_values($store_mini_auth_icp->firstErrors)));
  875. }
  876. $statusText = '';
  877. $pic_url = '';
  878. if (!intval($result['is_finish'])) {
  879. $statusText = StoreMiniAuthIcp::FACE_STATUS_NAME[$result['face_status']];
  880. if (intval($result['face_status']) === StoreMiniAuthIcp::FACE_STATUS_SUCCESS) {
  881. if (intval($result['face_along_with_auth_result']) === StoreMiniAuthIcp::ALONG_WITH_AUTH_NO) {
  882. $statusText = '等待认证短信核验';
  883. }
  884. $result['face_status'] = StoreMiniAuthIcp::FACE_STATUS_WAITING;
  885. }
  886. if (in_array($result['face_status'], [StoreMiniAuthIcp::FACE_STATUS_INIT, StoreMiniAuthIcp::FACE_STATUS_WAITING])) {
  887. $result['face_status'] = StoreMiniAuthIcp::FACE_STATUS_WAITING;
  888. }
  889. // if (!empty($store_mini_auth_icp->face_verify_url)) {
  890. // $pic_url = $this->setPicUrl($store_mini_auth_icp->face_verify_url, $store_mini_auth_icp->id, 'verify');
  891. // $store_mini_auth_icp->face_verify_qrcode_url = $pic_url;
  892. // $store_mini_auth_icp->save();
  893. // }
  894. }
  895. return [
  896. 'code' => 0,
  897. 'msg' => '',
  898. 'data' => [
  899. // 'face_is_finish' => intval($result['is_finish']),
  900. 'face_status_text' => $statusText,
  901. 'face_status' => $result['face_status'],
  902. 'face_verify_qrcode_url' => $store_mini_auth_icp->face_verify_url
  903. ]
  904. ];
  905. } catch (\Exception $e) {
  906. return [
  907. 'code' => 1,
  908. 'msg' => $e->getMessage()
  909. ];
  910. }
  911. }
  912. /**
  913. * 发起小程序管理员人脸核身
  914. */
  915. public function createVerifyTask() {
  916. try {
  917. $cache = cache();
  918. //请求微信接口
  919. $app = $this->app;
  920. if (!$app) {
  921. throw new \Exception('获取小程序信息失败');
  922. }
  923. $store_id = $this->store_id;
  924. $mini_id = $this->mini_id;
  925. $store_mini_icp = StoreMiniAuthIcp::findOne(['mini_id' => $mini_id, 'is_delete' => 0]);
  926. $open = false;
  927. if ($store_mini_icp) {
  928. $key = 'mini_auth_icp_' . $store_mini_icp->id;
  929. if ($cache->get($key)) {
  930. $open = true;
  931. };
  932. }
  933. if ($open) {
  934. if (intval($store_mini_icp->face_is_finish)) {
  935. throw new \Exception('人脸核身已经通过');
  936. }
  937. if (!empty($store_mini_icp->task_id)) {
  938. throw new \Exception('人脸核身检验中 请及时处理或联系管理员');
  939. }
  940. }
  941. $data = [
  942. 'along_with_auth' => true
  943. ];
  944. $client = new BaseClient($app);
  945. $result = $client->httpPostJson('wxa/icp/create_icp_verifytask', $data);
  946. //返回微信信息
  947. if ($result['errcode'] !== 0) {
  948. throw new \Exception($result['errmsg'], $result['errcode']);
  949. }
  950. // TODO 首次猜测可能每个小程序备案一次
  951. //保存人脸核验任务id task_id
  952. if (!$store_mini_icp) {
  953. $store_mini_icp = new StoreMiniAuthIcp();
  954. }
  955. $store_mini_icp->task_id = $result['task_id'];
  956. $store_mini_icp->store_id = $store_id;
  957. $store_mini_icp->mini_id = $mini_id;
  958. $store_mini_icp->created_at = time();
  959. if (!$store_mini_icp->save()) {
  960. throw new \Exception(json_encode($store_mini_icp->errors, JSON_UNESCAPED_UNICODE));
  961. }
  962. $pic_url = '';
  963. if (!empty($result['verify_url'])) {
  964. $pic_url = $this->setPicUrl($result['verify_url'], $store_mini_icp->id, 'verify');
  965. $store_mini_icp->face_verify_qrcode_url = $pic_url;
  966. $store_mini_icp->face_verify_url = $result['verify_url'];
  967. $store_mini_icp->save();
  968. }
  969. $cache->set('mini_auth_icp_' . $store_mini_icp->id, 1, 600);
  970. return [
  971. 'code' => 0,
  972. 'msg' => '已发送人脸核身',
  973. 'data' => [
  974. 'task_id' => $result['task_id'],
  975. 'face_verify_qrcode_url' => $pic_url
  976. ]
  977. ];
  978. } catch (\Exception $e) {
  979. return [
  980. 'code' => $e->getCode() ?: 1,
  981. 'msg' => $e->getMessage()
  982. ];
  983. }
  984. }
  985. public function setPicUrl($auth_url, $id, $type = 'pay') {
  986. $filename = md5(date('Ym') . 'mini_auth_icp' . $id . '_' . $type);
  987. $path = \Yii::$app->runtimePath . '/image/' . $filename . '.jpg';
  988. $pic_url = str_replace('http://', 'https://', \Yii::$app->request->hostInfo . '/runtime/image/' . $filename . '.jpg');
  989. QrCode::image($auth_url, 500, false, 'L', 'JPEG', 0, ['255,255,255', '0,0,0'], 1, false, $path);
  990. return $pic_url;
  991. }
  992. //获取网络图片到临时目录
  993. private function saveTempImage($url)
  994. {
  995. if (strpos($url, 'http') === false) {
  996. $url = 'http:' . trim($url);
  997. }
  998. if (!is_dir(\Yii::$app->runtimePath . '/image')) {
  999. mkdir(\Yii::$app->runtimePath . '/image');
  1000. }
  1001. $save_path = \Yii::$app->runtimePath . '/image/' . md5($url) . '.jpg';
  1002. CurlHelper::download($url, $save_path);
  1003. return $save_path;
  1004. }
  1005. }