file_get_contents 讀取文件元素
str_replace('舊的標識',"新的替換標識",'所有元素')
file_put_contents 保存文件元素
我們通過控制器讀取模板頁面,通過默認標識{%ios_url%} {%android_url%}替換路徑
控制器
public function downloadUrl(Request $request)
{
$validator = Validator::make($request->all(), [
'ios_url' => 'required|string',
'android_url' => 'required|string',
]);
if ($validator->fails()) {
return response_json(402, $validator->errors()->first());
}
$ios_url = $request->input('ios_url');
$android_url = $request->input('android_url');
//獲取庫中存的路徑
$info = AppVersion::select('download_url')->get()->toArray();
$oldAndroidUrl = '{%android_url%}';
$oldIosUrl = '{%ios_url%}';
$indexHtml = file_get_contents(public_path('self_template/index.html'));
$indexHtml = str_replace($oldIosUrl, $ios_url, $indexHtml);
$indexHtml = str_replace($oldAndroidUrl, $android_url, $indexHtml);
file_put_contents(public_path('web/index.html'), $indexHtml);
$downloadHtml = file_get_contents(public_path('self_template/download.html'));
$downloadHtml = str_replace($oldIosUrl, $ios_url, $downloadHtml);
$downloadHtml = str_replace($oldAndroidUrl, $android_url, $downloadHtml);
file_put_contents(public_path('client/share/download.html'), $downloadHtml);
$inviteCnHtml = file_get_contents(public_path('self_template/invite-cn.html'));
$inviteCnHtml = str_replace($oldIosUrl, $ios_url, $inviteCnHtml);
$inviteCnHtml = str_replace($oldAndroidUrl, $android_url, $inviteCnHtml);
file_put_contents(public_path('client/share/invite-cn.html'), $inviteCnHtml);
AppVersion::where('id', 1)->update(['download_url' => $android_url]);
AppVersion::where('id', 2)->update(['download_url' => $ios_url]);
return response_json(200, trans('app.success'));
}
模板頁面
<div class="download">
<br/>
<br/>
<br/>
<div class="iosBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
安裝完成後需要設置信任,手動設置步驟
【設置】 -> 【通用】-> 【描述文件與設備管理】
</p>
<a href="{%ios_url%}" id="phoneIos" class="IsPhone ios">
<p class="ios" onclick="iosClick()">
<span>蘋果版下載</span>
</p>
<!--<p><img src="img/ios-qrcode.png?t=0.75272" alt="" class="qrcode" /></p>-->
</a>
</div>
<div class="androidBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
<br>
<br>
</p>
<a href="{%android_url%}" id="phoneAndroid" class="IsPhone android">
<p class="Android">
<span>安卓版下載</span>
</p>
<!--<p><img src="img/android-qrcode.png?t=0.75272" alt="" class="qrcode"/></p>-->
</a>
</div>
</div>
靜態頁面
<div class="download">
<br/>
<br/>
<br/>
<div class="iosBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
安裝完成後需要設置信任,手動設置步驟
【設置】 -> 【通用】-> 【描述文件與設備管理】
</p>
<a href="https://####/cn/app/%E9%93%BE%E7%B3%BB/id1489448519" id="phoneIos" class="IsPhone ios">
<p class="ios" onclick="iosClick()">
<span>蘋果版下載</span>
</p>
<!--<p><img src="img/ios-qrcode.png?t=0.75272" alt="" class="qrcode" /></p>-->
</a>
</div>
<div class="androidBox">
<p style="color: #000a39;font-size: 12px;width: 250px;margin: 0 auto;text-align: left;">
<br>
<br>
</p>
<a href="https://####/client/share/download/Android-2019-10-24/ChainChat.apk" id="phoneAndroid" class="IsPhone android">
<p class="Android">
<span>安卓版下載</span>
</p>
<!--<p><img src="img/android-qrcode.png?t=0.75272" alt="" class="qrcode"/></p>-->
</a>
</div>
</div>