자료실

부자는 돈을 써서 시간을 아끼지만 가난한 사람은 시간을 써서 돈을 아낀다

vb.net

IT HUB를 찾아주셔서 감사합니다.

기타 [vb.net] 네이버 스마트 스토어 커머스 API 활용하기 - 주문 조회

페이지 정보

profile_image
작성자 하나를하더라도최선을
댓글 0건 조회 4,845회 작성일 23-06-26 17:46

본문

URL :

https://api.commerce.naver.com/external/v1/pay-order/seller/product-orders/last-changed-statuses

lastChangedFrom

required

 

string <date-time>

Example: 아래 "한국 표준시(KST)" 참고

조회 시작 일시(inclusive)

lastChangedTo

string <date-time>

조회 종료 일시(inclusive). 생략 시 lastChangedFrom으로부터 24시간 후로 자동 지정됩니다.

lastChangedType

string

최종 변경 구분

moreSequence

string

moreSequence 사용법은 API 설명을 참고합니다. 임의의 값 입력 시 예기치 않은 결과가 제공될 수 있습니다.

limitCount

integer

조회 응답 개수 제한. 생략하거나 300을 초과하는 값을 입력하면 최대 300개의 내역을 제공합니다.

'한국 표준시(KST)' 2022년 9월 29일 오후 5시 32분 6초를 구성할 경우 아래와 같습니다. (UTC+9)

2022-09-29T17:32:06.000+09:00

GET 메소드 형식의 API를 사용하는 경우

2022-09-29T17:32:06.010+09:00 → 2022-09-29T17:32:06.010%2B09:00

lastChangedType :

코드

설명

비고

PAY_WAITING

결제 대기

 

PAYED

결제 완료

 

EXCHANGE_OPTION

옵션 변경

선물하기

DELIVERY_ADDRESS_CHANGED

배송지 변경

 

GIFT_RECEIVED

선물 수락

선물하기

CLAIM_REJECTED

클레임 철회

 

DISPATCHED

발송 처리

 

CLAIM_REQUESTED

클레임 요청

 

COLLECT_DONE

수거 완료

 

CLAIM_HOLDBACK_RELEASED

클레임 보류 해제

 

CLAIM_COMPLETED

클레임 완료

 

PURCHASE_DECIDED

구매 확정

 


 


Imports System.Runtime.CompilerServices
Imports BCrypt.Net
Namespace nhn
    Module _nhn_
        Public client_id As String = "app id"
        Public client_secret As String = "secret key"
        Public access_token As String = ""
        Const User_Agent As String = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.9 Safari/537.36"
 
        Public Function get_token() As String
            Dim timestamp As Long = CLng(DateTime.UtcNow.Subtract(New DateTime(197011)).TotalMilliseconds)
            Dim pwd = String.Format("{0}_{1}", client_id, timestamp.ToString)
            pwd = BCrypt.Net.BCrypt.HashPassword(pwd, client_secret)
            Dim client_secret_sign As String = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(pwd))
 
            Dim T As String, URL As String = "https://api.commerce.naver.com/external/v1/oauth2/token"
            T.addPostData("grant_type""client_credentials")
            T.addPostData("client_id", client_id)
            T.addPostData("timestamp", timestamp)
            T.addPostData("client_secret_sign", client_secret_sign)
            T.addPostData("type""SELF")
 
            With CreateObject("WinHttp.WinHttpRequest.5.1")
                .Open("POST", URL)
                .SetRequestHeader("Connection""Keep-Alive")
                .SetRequestHeader("Content-Type""application/x-www-form-urlencoded; Charset=UTF-8")
                .SetRequestHeader("Accept""text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
                .SetRequestHeader("Accept-Language""ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3")
                .SetRequestHeader("Host""api.commerce.naver.com")
                .SetRequestHeader("User-Agent", User_Agent)
                .SetRequestHeader("Content-Length", T.Length)
                .Send(T)
                .WaitForResponse() : Application.DoEvents()
                T = .ResponseText
            End With
            Dim O As Object = JSON.DeserializeObject(T) ': Clipboard.SetText(O.ToString) : Stop
            access_token = O("access_token")
            Return access_token
        End Function
 
 
        Public Function orders(ds As Date, de As DateAs DataTable
            If access_token.Length = 0 Then get_token()
            Dim T As String, URL As String = "https://api.commerce.naver.com/external/v1/pay-order/seller/product-orders/last-changed-statuses?"
            URL &= "lastChangedFrom=" & ds.ToString("yyyy-MM-dd""T""HH:mm:ss"".000%2B09:00""")
            URL &= "&lastChangedTo=" & de.ToString("yyyy-MM-dd""T""HH:mm:ss"".000%2B09:00""")
            'URL &= "lastChangedType="  '// #최종변경구분(PAYED : 결제완료, DISPATCHED : 발송처리)
            'URL &= "moreSequence="
            URL &= "&limitCount=300"
 
            With CreateObject("WinHttp.WinHttpRequest.5.1")
                .Open("GET", URL)
                .SetRequestHeader("Host""api.commerce.naver.com")
                .SetRequestHeader("User-Agent", User_Agent)
                .SetRequestHeader("Accept""text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8")
                .SetRequestHeader("Accept-Language""ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3")
                .SetRequestHeader("Connection""keep-alive")
                .SetRequestHeader("Upgrade-Insecure-Requests""1")
                .SetRequestHeader("Authorization""Bearer " & access_token)
                .Send()
                .WaitForResponse() : Application.DoEvents()
                T = System.Text.Encoding.UTF8.GetString(.ResponseBody)
            End With
            Dim O As Object = JSON.DeserializeObject(T)
            Dim D As DataTable = JSON.ToDataTable(O, "data lastChangeStatuses")
            Return D
        End Function
    End Module
End Namespace
 
 
Public Module UnixTime
    Const UnixEraStartTicks As Long = 621355968000000000
    <Extension> Public Function UnixTimestamp(value As DateAs Long
        Dim UnixEraTicks = value.Ticks - UnixEraStartTicks
        Return UnixEraTicks \ 10000
    End Function
    Public Function DateFromUnix(timestamp As Long) As Date
        Return New Date(UnixEraStartTicks + timestamp * 10000)
    End Function
End Module
 




    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i As Integer, de As Date, ds As Date, s As DataTable, D As DataTable = DataGridView1.DataSource
        Dim R As DataRow, T As String
        If D Is Nothing Then D = New DataTable
        D.Rows.Clear()
        de = Now
        Do
            ds = de.AddDays(-1)
            s = nhn.orders(ds, de)
            de = ds
            If s IsNot Nothing Then
                If s.Rows.Count > 0 Then
                    For Each C As DataColumn In s.Columns
                        If Not D.Columns.Contains(C.ColumnName) Then D.Columns.Add(C.ColumnName, C.DataType)
                    Next
                    For Each x As DataRow In s.Rows
                        R = D.NewRow
                        For Each C As DataColumn In s.Columns
                            T = x(C.ColumnName)
                            Select Case T
                                Case "PAY_WAITING" : T = "결제 대기"
                                Case "PAYED" : T = "결제 완료"
                                Case "EXCHANGE_OPTION" : T = "옵션 변경(선물하기)"
                                Case "DELIVERY_ADDRESS_CHANGED" : T = "배송지 변경"
                                Case "GIFT_RECEIVED" : T = "선물 수락(선물하기)"
                                Case "CLAIM_REJECTED" : T = "클레임 철회"
                                Case "DISPATCHED" : T = "발송 처리"
                                Case "CLAIM_REQUESTED" : T = "클레임 요청"
                                Case "COLLECT_DONE" : T = "수거 완료"
                                Case "CLAIM_HOLDBACK_RELEASED" : T = "클레임 보류 해제"
                                Case "CLAIM_COMPLETED" : T = "클레임 완료"
                                Case "PURCHASE_DECIDED" : T = "구매 확정"
                            End Select
                            R(C.ColumnName) = t
                        Next
                        D.Rows.Add(R)
                    Next
                End If
            End If
            i += 1
        Loop Until i > 15
        DataGridView1.DataSource = D
        DATAGRIDVIEW_DEFAULT_SETTING(DataGridView1)
    End Sub


ce888f01ee5a936e000338975409641e_1687769073_8404.png
 

댓글목록

등록된 댓글이 없습니다.