Ver Fonte

充值码

shish há 1 ano atrás
pai
commit
dd70615e9f

+ 1 - 1
app-hd/controllers/RechargeController.php

@@ -26,7 +26,7 @@ class RechargeController extends BaseController
         $page = 'pages/member/recharge';
         $ptStyle = dict::getDict('ptStyle', 'mall');
         $scene = 'a=' . $this->shopAdminId . '&s=' . $this->shopId;
-        $imgUrl = miniUtil::generateUnlimitedMiniCode($merchant, $page, $scene, $ptStyle);
+        $imgUrl = miniUtil::generateUnlimitedRechargeMiniCode($merchant, $page, $scene, $ptStyle);
 
         $prefix = imgUtil::getPrefix();
         $titleBase64 = stringUtil::ossBase64('扫码充值');

+ 31 - 0
common/components/miniUtil.php

@@ -1592,6 +1592,37 @@ class miniUtil
         return $behind . $fileName;
     }
 
+    //生成充值码,永久有效,数量暂无限制 ssh 20250307
+    public static function generateUnlimitedRechargeMiniCode($merchant, $page, $scene = '', $ptStyle = 0)
+    {
+        $id = isset($merchant['id']) ? $merchant['id'] : 0;
+        $fileName = md5($page . '_' . $scene) . '.jpg';
+        $behind = 'retail/rechargeCode/' . date("Ym") . '/' . date("d") . '/' . $id . '/';
+        $filePath = dirUtil::getImgDir() . $behind;
+        if (!file_exists($filePath)) {
+            mkdir($filePath, 0777, true);
+        }
+        $file = $filePath . $fileName;
+        if (file_exists($file)) {
+            return $behind . $fileName;
+        }
+        $accessToken = self::getMiniProgramAccessToken($merchant, $ptStyle);
+        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token={$accessToken}";
+        $curl = new curl\Curl();
+        $data = [];
+        if (!empty($page)) {
+            $data["page"] = $page;
+        }
+        $data["scene"] = $scene;
+        $result = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))->post($url);
+        Yii::info('获取小程序图片资源:' . json_encode($result));
+        file_put_contents($file, $result);
+        //上传oss
+        $obj = $behind . $fileName;
+        $obj = ltrim($obj, "/");
+        oss::uploadImage($obj, $file);
+        return $behind . $fileName;
+    }
 
     //微信开放平台获取component_access_token
     public static function getComponentAccessToken($open)