T

어플과 php 통신

다음 소스는 제가 현재 사용중인 통신처리 내용 일부입니다.

[code]
<?php
/*
 * 설명: 매장 개설 처리부
 * 전달값: user_id, name, company_num, company_num_img, owner_name, addr, phone, bank_num_img, identify_img, sign_img, subject, content, store_pic[], level, user_type
 * 반환값: 
 */
include_once('_common.php');

# 템프 저장소 생성 및 퍼미션 변경
if(mkdir('./temp', 0707, true))
@chmod('./temp', 0707);

# 실제 저장소 생성 및 퍼미션 변경
if(mkdir(G5_DATA_PATH.'/app', 0707, true))
@chmod(G5_DATA_PATH.'/app', 0707);
if(mkdir(G5_DATA_PATH.'/app/store', 0707, true))
@chmod(G5_DATA_PATH.'/app/store', 0707);

# PATH 경로 잡음
$TempSavePath = './temp';
$SavePath = G5_DATA_PATH.'/app/store';

# 전달값 확인
if(!$_REQUEST['user_id']) die('회원정보 전달 값 없음');


# 데이터 복호화
$store_id    = TbDecrypt($_REQUEST['store_id']);
$user_id     = TbDecrypt($_REQUEST['user_id']);
$name        = TbDecrypt($_REQUEST['name']);
$company_num = TbDecrypt($_REQUEST['company_num']);
$owner_name  = TbDecrypt($_REQUEST['owner_name']);
$addr        = TbDecrypt($_REQUEST['addr']);
$phone       = TbDecrypt($_REQUEST['phone']);
$subject     = TbDecrypt($_REQUEST['subject']);
$content     = TbDecrypt($_REQUEST['content']);
$level       = TbDecrypt($_REQUEST['level']);
$user_type   = TbDecrypt($_REQUEST['user_type']);


# 상점 정보를 찾아본다.
//$StoreData = $tb->GetQuery(" select * from `{$xe['store_table']}` where `store_id` = '{$store_id}' ");

# 조건에 따른 sql 구조문 만듬
if($store_id) { // 매장이 있다면

$sql_head = " update `{$xe['store_table']}` set ";
$sql_body = "";
$sql_tail = "where `idx` = '{$store_id}' ";
}
else { // 매장이 없다면

$sql_head = " insert into `{$xe['store_table']}` set ";
$sql_body = " `user_id` = '{$user_id}', ";
$sql_tail = "";
}

# 이미지 작업 처리 작업
if($_REQUEST['company_num_img']) { // 사업자등록증 사본

$company_num_img_data = $tb->binary2images($TempSavePath, $SavePath, $store_id.'_company_num_img_'.time().'.jpg', $_REQUEST['company_num_img']);
if($company_num_img_data['name']) $sql_body .= " `company_num_img` = '".G5_URL."/app/store/{$company_num_img_data['name']}', ";
}
if($_REQUEST['bank_num_img']) { // 통장사본

$bank_num_img_data = $tb->binary2images($TempSavePath, $SavePath, $store_id.'_bank_num_img_'.time().'.jpg', $_REQUEST['bank_num_img']);
if($bank_num_img_data['name']) $sql_body .= " `bank_num_img` = '".G5_URL."/app/store/{$bank_num_img_data['name']}', ";
}
if($_REQUEST['identify_img']) { // 예금주 신분증 사본

$identify_img_data = $tb->binary2images($TempSavePath, $SavePath, $store_id.'_identify_img_'.time().'.jpg', $_REQUEST['identify_img']);
if($identify_img_data['name']) $sql_body .= " `identify_img` = '".G5_URL."/app/store/{$identify_img_data['name']}', ";
}
if($_REQUEST['sign_img']) { // 예금주 신분증 사본

$sign_img_data = $tb->binary2images($TempSavePath, $SavePath, $store_id.'_sign_img_'.time().'.jpg', $_REQUEST['sign_img']);
if($sign_img_data['name']) $sql_body .= " `sign_img` = '".G5_URL."/app/store/{$sign_img_data['name']}', ";
}
if($_REQUEST['store_pic'][0]) { // 매장사진

$StorePic = '';

for($i=0; $i<count($_REQUEST['store_pic']); $i++) {

if($_REQUEST['store_pic'][$i]) {

$store_picData = '';
$store_picData[$i] = $tb->binary2images($TempSavePath, $SavePath, $store_id.'_store_pic_'.$i.'_'.time().'.jpg', $_REQUEST['store_pic'][$i]);
$StorePic .= G5_URL."/app/store/{$store_picData[$i]['name']}\\r\\n";
}
}

if($StorePic) $sql_body .= " `store_pic` = '{$StorePic}', ";
}

# 업데이트 날짜 설정
$Diff = date('Y-m-d H:i:s');

$sql  = $sql_head;
$sql .= $sql_body;
$sql .= " `name` = '{$name}', ";
$sql .= " `company_num` = '{$company_num}', ";
$sql .= " `owner_name` = '{$owner_name}', ";
$sql .= " `addr` = '{$addr}', ";
$sql .= " `phone` = '{$phone}', ";
$sql .= " `subject` = '{$subject}', ";
$sql .= " `content` = '{$content}', ";
$sql .= " `level` = '{$level}', ";
$sql .= " `user_type` = '{$user_type}', ";
$sql .= " `diff` = '{$Diff}' ";
$sql .= $sql_tail;
sql_query($sql);


# 상점 정보를 다시 확인
$data = $tb->GetQuery(" select * from `{$xe['store_table']}` where `user_id` = '{$user_id}' ");


# 조건에 부합하는 출력 내용을 xml형태로 반환
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<data>'.PHP_EOL;
echo $tb->array2xml3($Data);
echo '</data>'.PHP_EOL;
[/code]

동작도: 어플 요청->php에서 필수 값 확인-> 전달값 복호화-> 바이러니 이미지 처리-> 값에 따른 insert or update 구분 하여 sql문 만듬-> 요청 값 반환

중요한점: 어플 내부 DB에도 같은 DB를 저장하여 신규로 발생 하는 DB를 서버로 전송하여 처리 한다. db마다 존재하는 `diff time`을 비교하여 마지막 발생 시점과 현재 타임과 비교하여 사이 데이터를 모두 다운받는다.


여러분은 어떤식으로 처리 하시나요?
|

댓글 2개

syntax highlight code 적용해 놓았습니다.
감사합니다!! 센스쟁이!!

주제가 무겁나보네요 ㅎㅎ
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
11년 전 조회 1,072
11년 전 조회 2,707
11년 전 조회 1,353
11년 전 조회 2,629
11년 전 조회 1,995
11년 전 조회 2,506
11년 전 조회 1,457
11년 전 조회 2,593
11년 전 조회 1,392
11년 전 조회 1,092
11년 전 조회 1,099
11년 전 조회 5,469
11년 전 조회 1,277
11년 전 조회 841
11년 전 조회 805
11년 전 조회 1,157
11년 전 조회 1,512
11년 전 조회 1,926
11년 전 조회 2,235
11년 전 조회 1,144
11년 전 조회 1,468
11년 전 조회 1,402
11년 전 조회 1,047
11년 전 조회 801
11년 전 조회 2,236
11년 전 조회 1,469
11년 전 조회 3,317
11년 전 조회 1,207
11년 전 조회 1,049
11년 전 조회 2,144
11년 전 조회 2,801
11년 전 조회 2,172
11년 전 조회 3,199
11년 전 조회 1,578
11년 전 조회 3,328
11년 전 조회 845
11년 전 조회 1,143
11년 전 조회 2,024
11년 전 조회 2,361
11년 전 조회 1,046
11년 전 조회 2,871
11년 전 조회 3,064
11년 전 조회 1,587
11년 전 조회 2,257
11년 전 조회 1,104
11년 전 조회 1,457
11년 전 조회 1,127
11년 전 조회 2,324
11년 전 조회 2,229
11년 전 조회 1,227
11년 전 조회 5,350
11년 전 조회 2,403
11년 전 조회 3,114
11년 전 조회 1,970
11년 전 조회 1,009
11년 전 조회 2,083
11년 전 조회 2,211
11년 전 조회 1,929
11년 전 조회 1,531
11년 전 조회 1,006
11년 전 조회 1,897
11년 전 조회 2,617
11년 전 조회 1,349
11년 전 조회 2,833
11년 전 조회 1,778
11년 전 조회 4,531
11년 전 조회 1,899
11년 전 조회 2,557
11년 전 조회 3,773
11년 전 조회 1,637
11년 전 조회 2,506
11년 전 조회 867
11년 전 조회 1,902
11년 전 조회 4,539
11년 전 조회 1,666
11년 전 조회 1,916
11년 전 조회 799
11년 전 조회 1,198
11년 전 조회 1,515
11년 전 조회 1,625
11년 전 조회 1,530
11년 전 조회 2,288
11년 전 조회 1,208
11년 전 조회 3,124
11년 전 조회 3,317
11년 전 조회 1,876
11년 전 조회 4,801
11년 전 조회 9,943
11년 전 조회 2,673
11년 전 조회 1,160
11년 전 조회 3,301
11년 전 조회 2,627
11년 전 조회 2,156
11년 전 조회 1,066
11년 전 조회 4,285
11년 전 조회 755
11년 전 조회 1,276
11년 전 조회 1,720
11년 전 조회 1,937
11년 전 조회 1,904
🐛 버그신고