외부쇼핑몰에서 포인트를 전송받는 페이지

외부쇼핑몰에서 포인트를 전송받는 페이지

QA

외부쇼핑몰에서 포인트를 전송받는 페이지

본문

A라는 외부쇼핑몰에서 제가 만든 B라는 그누보드 사이트에 포인트를 전송하는 기능을 준비하고 있는데요,
저희 B사이트에 회원정보 확인 및 포인트를 받을 수 있는 페이지를 준비해서 URL을 달라고합니다. 어떤식으로 준비해서 제공하면 되는거죠?
A사이트에서 POST 방식으로 회원아이디와 포인트값을 보내면 B사이트에서 그것을 확인하고 해당 회원에게 포인트를 넣어주면 되는 흐름 같은데 어떻게하면 되는지 좀 막연합니다. 이런식의 API 제공예시가 있을까요 

이 질문에 댓글 쓰기 :

답변 3

받아서 처리할 파일을 만드셔서 드리면 됩니다. 변수명도 지정해서요

저희 게시판 글쓰기 하면 write_update.php 로 넘어가잖아요 action이

그런 의미라고 보시면 됩니다.

 

예를들어 post_update.php를 만들고

$point = isset($_POST['point']) ? $_POST['point'] : '';

 

이런식의 데이터를 받아다가

db에 저장을 하시는 작업을 할 페이지 url을 달라고 하는겁니다~

간단하게는 다음처럼 구성하는 방법이 있습니다.


<?php
/**
 *
 * file : ${DOCUMENT_ROOT}/api/member/index.php
 * uri : yourdomain.tld/api/member/
 * params-get : mb_id
 * params-post : mb_id, mb_point
 */
 
$doc_root = dirname(dirname(__DIR__));
require $doc_root . DIRECTORY_SEPARATOR . 'common.php';
 
header('Content-Type: application/json; charset=utf-8');
 
$req_method = $_SERVER['REQUEST_METHOD'];
$err = null;
$res = [];
 
if ($req_method == 'GET') {
    $mb_id = isset($_GET['mb_id']) == true ? sql_escape_string($_GET['mb_id']) : null;

    if (empty($mb_id) == false) {
        $res = get_member($mb_id, 'mb_id, mb_name, mb_level, mb_point');
    }
 
    if (empty($res['mb_id']) == true) {
        $err = true;
    }
} else if ($req_method == 'POST') {
    $mb_id = isset($_POST['mb_id']) == true ? sql_escape_string($_POST['mb_id']) : null;
    $mb_point = isset($_POST['mb_point']) == true ? (int)$_POST['mb_point'] : 0;
    $result = 0;
 
    $mbinfo = get_member($mb_id);

    if (empty($mbinfo['mb_id']) == false) {
        $result = insert_point($mb_id, $mb_point, 'from external shop');
    }
 
    if ($result == 1) {
        $res = ['code' => 0, 'message' => 'SUCCESS'];
    } else {
        $err = true;
    }
}
 
if ($err == true) {
    $res = ['code' => 456, 'message' => 'FAILURE'];
}
echo json_encode($res);
?>

전달되는 회원 아이디, 포인트에 대한 상세 설명이 없으니 변수명을 mb_id, mb_point로 함

 

1. root에 shop_point.php 화일 생성

2. 내용

<?php

include_once("_common.php");

$member_table= $g5['member_table'];

if( !isset($mb_id) || !isset($mb_point) || $mb_point<0 ) die('error');

$row= sql_fetch("select mb_id from $member_table where mb_id='$mb_id' ");

if(!$row['mb_id']) die('error');

 insert_point($mb_id, $mb_point, "shop point", G5_TIME_YMDHIS, '외부shop');

die('OK');

 

http://도메인/shop_point.php 전달

변수명은 mb_id, mb_point 로 해달라고 전달

 

 

 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 33
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT