AlipayUploadController.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\admin\controllers\setting;
  8. use app\modules\admin\controllers\BaseController;
  9. use app\models\Option;
  10. use app\modules\admin\models\WechatThirdForm;
  11. use app\utils\ShareQrcode;
  12. use app\utils\Alipay\alipaySdk\aop\request\AlipayOpenAppQrcodeCreateRequest;
  13. class AlipayUploadController extends BaseController
  14. {
  15. private $url = 'http://chidian.we10.cn/';
  16. /**
  17. * 获取小程序码
  18. *
  19. * @return void
  20. */
  21. public function actionQrcode()
  22. {
  23. try {
  24. $request = new AlipayOpenAppQrcodeCreateRequest();
  25. $param = [
  26. 'url_param' => 'pages/home/home',
  27. 'query_param' => 'a=1',
  28. 'describe' => "小程序开发上线使用"
  29. ];
  30. $res = ShareQrcode::aliConfigQr($request, $param);
  31. if ($res->code !== "10000") {
  32. return $this->asJson([
  33. 'code' => 1,
  34. 'msg' => $res->sub_msg,
  35. ]);
  36. }
  37. return $this->asJson([
  38. 'code' => 0,
  39. 'msg' => 'success',
  40. 'data' => $res->qr_code_url_circle_blue,
  41. ]);
  42. } catch (\Exception $e) {
  43. return $this->asJson([
  44. 'code' => 1,
  45. 'msg' => $e->getMessage(),
  46. ]);
  47. }
  48. }
  49. /**
  50. * 登录
  51. *
  52. * @return void
  53. */
  54. public function actionLogin()
  55. {
  56. set_time_limit(0);
  57. $conf = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value'];
  58. if($conf){
  59. $conf = json_decode($conf, true);
  60. }
  61. if(!$conf || empty($conf['app_id'])){
  62. return $this->asJson([
  63. 'code' => 1,
  64. 'msg' => '请先配置支付宝AppId',
  65. ]);
  66. }
  67. $appid = $conf['app_id'];
  68. $url = $this->url . 'login_alipay.php';
  69. $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo);
  70. $ws_url = isset(\Yii::$app->params['ws_url']) ? \Yii::$app->params['ws_url'] : 'ws.cyyvip.com';
  71. $res = http_get($url, [
  72. 'query' => [
  73. 'appid' => $appid,
  74. 'http_url' => $host,
  75. 'version' => cyy_version(),
  76. 'ws_url' => $ws_url,
  77. 'store_id' => get_store_id(),
  78. ]
  79. ]);
  80. if ($res->getStatusCode() != 200) {
  81. return $this->asJson([
  82. 'code' => 1,
  83. 'msg' => '请求出错!',
  84. ]);
  85. }
  86. $content = json_decode((string)$res->getBody());
  87. return $this->asJson($content);
  88. }
  89. /**
  90. * 上传小程序
  91. *
  92. * @return void
  93. */
  94. public function actionPreview()
  95. {
  96. set_time_limit(0);
  97. $conf = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value'];
  98. if($conf){
  99. $conf = json_decode($conf, true);
  100. }
  101. if(!$conf || empty($conf['app_id'])){
  102. return $this->asJson([
  103. 'code' => 1,
  104. 'msg' => '请先配置支付宝AppId',
  105. ]);
  106. }
  107. $appid = $conf['app_id'];
  108. $url = $this->url . 'preview_alipay.php';
  109. $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo);
  110. $res = http_get($url, [
  111. 'query' => [
  112. 'appid' => $appid,
  113. 'http_url' => $host,
  114. 'version' => cyy_version(),
  115. 'store_id' => get_store_id(),
  116. ],
  117. 'timeout' => 500,
  118. ]);
  119. if ($res->getStatusCode() != 200) {
  120. return $this->asJson([
  121. 'code' => 1,
  122. 'msg' => '请求出错!',
  123. ]);
  124. }
  125. $content = json_decode((string)$res->getBody());
  126. return $this->asJson($content);
  127. }
  128. /**
  129. * 上传小程序
  130. *
  131. * @return void
  132. */
  133. public function actionUpload()
  134. {
  135. set_time_limit(0);
  136. $conf = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value'];
  137. if($conf){
  138. $conf = json_decode($conf, true);
  139. }
  140. if(!$conf || empty($conf['app_id'])){
  141. return $this->asJson([
  142. 'code' => 1,
  143. 'msg' => '请先配置支付宝AppId',
  144. ]);
  145. }
  146. $appid = $conf['app_id'];
  147. $url = $this->url . 'upload_alipay.php';
  148. $host = str_replace(['http://', 'https://'], ['', ''], \Yii::$app->request->hostInfo);
  149. $res = http_get($url, [
  150. 'query' => [
  151. 'appid' => $appid,
  152. 'http_url' => $host,
  153. 'version' => cyy_version(),
  154. 'store_id' => get_store_id(),
  155. ],
  156. 'timeout' => 500,
  157. ]);
  158. if ($res->getStatusCode() != 200) {
  159. return $this->asJson([
  160. 'code' => 1,
  161. 'msg' => '请求出错!',
  162. ]);
  163. }
  164. $content = json_decode((string)$res->getBody());
  165. return $this->asJson($content);
  166. }
  167. public function actionPublic()
  168. {
  169. $conf = Option::get(Option::OPTOPN_KEY, get_store_id(), 'alipay')['value'];
  170. if($conf){
  171. $conf = json_decode($conf, true);
  172. }
  173. if(!$conf || empty($conf['app_id'])){
  174. return $this->asJson([
  175. 'code' => 1,
  176. 'msg' => '请先配置支付宝AppId',
  177. ]);
  178. }
  179. $appid = $conf['app_id'];
  180. $link = "https://open.alipay.com/mini/dev/sub/dev-manage?appId={$appid}&bundleId=com.alipay.alipaywallet";
  181. return $this->asJson([
  182. 'code' => 0,
  183. 'msg' => '添加成功',
  184. 'data' => [
  185. 'link' => $link,
  186. ],
  187. ]);
  188. }
  189. }