Интерфейс JS SDK Wechat необходим для открытия камеры мобильного телефона, чтобы делать снимки и сохранять их на сервере. Он в основном использует интерфейс JS SDK для съемки фотографий или выбора изображения из альбома мобильного телефона и загрузки изображения.
Справочный материал:
Справочный материал:
Справочный материал:
Во-первых: Представляем Wechat JS
2: Ввод конфигурации проверки разрешений через интерфейс конфигурации
wx.config(php echo Yii::$app->wechat->js->config([ 'chooseImage', 'uploadImage', 'downloadImage' ]) ?> );
3. Фотоинтерфейс терминала Wechat
wx.chooseImage({
Count: 1, // default 9
SizeType: ['original','compressed'], // You can specify whether it's an original or a compressed graph by default.
SorceType: ['album','camera'], // You can specify whether the source is an album or a camera by default.
success: function (res) {
Var localIds = res. localIds; // Returns the list of local IDs for the selected photos, which can be used as the SRC attribute of the IMG tag to display the images
}
});Четвертое: загрузка фотографий в интерфейс сервера Wechat
wx.uploadImage({
LocalId: LocalIds, // The local ID of the image to be uploaded, obtained by the chooseImage interface
IsShow ProgressTips: 1, // defaults to 1, showing progress hints
success: function (res) {
Var serverId = res.serverId; //Server-side ID returning pictures
},
fail: function() {
// Failed to upload pictures to Wechat server
return false;
}
});5. Загрузите фотографии серверов Wechat на локальные серверы
Внешний интерфейс:
// URL represents the PHP interface address
// SerrId represents the server-side ID of the image
$.post(url, {'media_id':serverId}, function(data) {
if (data.type == 'success') {
// Upload Success
} else {
// Upload failure
}
});PHP (интерфейс)
public function actionUpload()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$request = Yii::$app->request;
$mediaId = $request->post('media_id');
if (empty($mediaId)) {
return [
'type' => 'error',
'message'=>'parameter error! '
];
}
// Temporary material
$temporary = Yii::$app->wechat->material_temporary;
// Create a server directory
$path = 'wechat/' . date('Ymd',time()) . '/';
$fullPath = Yii::getAlias('@webroot') . '/' . $path;
if (!is_dir($fullPath)) {
FileHelper::createDirectory($fullPath);
}
// Set Image Name
$fileName = Yii::$app->getSecurity()->generateRandomString() . '-' . date('His',time());
// Download temporary material from server to local server
$temporary->download($mediaId, $fullPath, $fileName);
return [
'type' => 'success',
'url' => $path . $fileName . '.jpg',
];
}Интеграция интерфейсного кода
wechat->js->config([ 'chooseImage', 'uploadImage', 'downloadImage' ]); $JS = <<
registerJs($JS); ?>
Согласно приведенному выше коду, мы можем открыть камеру и сделать фотографии в терминале микро-почты, а затем сохранить фотографии на сервере.