1. Go to this page and download the library: Download cafe24corp/recipe-channel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
/**
* 트리거 동적 필드데이터를 레시피에 전달 합니다.
* 앱스토어 > 레시피관리 > 채널관리 에서 트리거 동적 필드 데이터 전달 URL 을 설정할 수 있습니다.
*
* 해당 필드는 dynamic 을 true 로 설정하여야 합니다.
* 요청은 POST 로 전달되면 동적 필드의 데이터를 로드하여 전달하셔야 합니다.
*/
use Cafe24corp\Recipe;
$recipe = new Recipe();
// 동적 필드 데이터 요청
/*
{
"data": [
{
"name": "collection"
}
...
]
}
*/
$data = $_POST['data'];
$dynamicFieldData = [];
for ($i = 0 ; $i < count($data) ; $i++){
$name = $data[$i]['name'];
//동적 데이터 생성
$dynamicFieldData = array_push ( $dynamicFieldData, doGetDynamicFieldData($name) );
}
// 레시피로 전달
/* 전달 데이터 샘플
{
"data": [
{
"name": "collection",
"options": [
{
"label": "Recommend Products",
"value": "123"
},
{
"label": "Hit Products",
"value": "456"
},
...
]
},
...
]
}
*/
// 결과 리턴
echo json_encode(['data' => $dynamicFieldData ]);
/**
* 각 채널에서 채널 사용자별로 "카페24 Recipe"에 전달해야 하는
* 트리거 이벤트 리스트가 변경되었다는 알림을 받기 위한 프로토콜입니다.
*
* 변경알림을 전달 받으면 전달받은 유저아이디로
* 유저별 트리거 리스트를 검색하여 결과 값을 채널쪽에 저장합니다.
*/
use Cafe24corp\Recipe;
use Cafe24corp\Exception;
$recipe = new Recipe();
try {
//채널 사용자 ID별 활성 트리거 변경 알림
$data = $_POST['data'];
/*
* POST 데이터 샘플
{
"data": [
{
"user_id": "userid1"
},
{
"user_id": "userid2"
},
...
]
}
*/
$result = [];
for ($i = 0 ; $i < count($data) ; $i++) {
$user_id = $data[$i]['user_id'];
$triggerData = $recipe->getActiveTriggerList($user_id);
/*
* 응답 데이터 샘플
{
"triggers": [
100001,
100002,
100004
]
}
*/
// 채널 측에 결과 저장
// doStoreTrigger()
$result[] = ['result' => true];
}
// 결과 리턴
echo json_encode($result);
}catch(Exception\RecipeException $e){
echo $e->getMessage();
exit;
}
/**
* 트리거 이벤트 전달
*/
use Cafe24corp\Recipe;
use Cafe24corp\Exception;
$recipe = new Recipe();
try {
// 트리거 아이디
$trigger_id = 100010;
// 채널측 유저 아이디
$user_id = 'jylee08'; //필요하지 않을 경우 전달하지 않아도 된다.
// 트리거 데이터 생성 (전달할 갯수만큼 루프
$triggerData = [];
for ($i = 0 ; $i < 1 ; $i++)
{
//데이터 예시 - 트리거 필드에 설정된 ID 값으로 전달 한다.
$value = [
'id' => 'id',
'message' => 'message'
];
$triggerData[] = $recipe->makeTriggerData($trigger_id, $value, $user_id);
}
// 트리거 이벤트 레시피로 전달
$recipe->sendTriggerEvent($triggerData);
}catch(Exception\RecipeException $e){
echo $e->getMessage();
exit;
}
use Cafe24corp\Recipe;
$recipe = new Recipe();
// 엑션 필드 정보 리턴
$url = __DIR__ . '/json/action.json';
echo $recipe->getActionData($url);
// 결과 리턴
echo json_encode($result);
use Cafe24corp\Recipe;
$recipe = new Recipe();
// 동적 필드 데이터 요청
$data = $_POST['data'];
$dynamicFieldData = [];
for ($i = 0 ; $i < count($data) ; $i++){
$name = $data[$i]['name'];
//동적 데이터 생성
$dynamicFieldData = array_push ( $dynamicFieldData, doGetDynamicFieldData($name) );
}
// 결과 리턴
echo json_encode(['data' => $dynamicFieldData ]);
/**
* 엑션 실행
* 앱스토어 > 레시피관리 > 채널관리 에서 액션에 사용하는 URL 을 설정할 수 있습니다.
*
*/
use Cafe24corp\Recipe;
$recipe = new Recipe();
$data = $_POST;
/*
{
"product_name": "상품명",
"category_no": "1"
}
*/
//Access Token 로드 - 엑션 처리시 사용
$access_token = $recipe->getBearerToken();
// 엑션처리
// $result = doAction($access_token, $data);
// 재료 반환 데이터 생성
/* 재료 반환 데이터 샘플
{
"data": [
{
"product_code": "P00000N",
"product_no": 100
}
]
}
*/
// 기본 재료 (엑션 데이터 재료 ID 를 key 로 사용한다. - 날짜, 시간 등
$ingredients = $recipe->makeIngredients();
echo json_encode($ingredients);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.