【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試_第1頁
【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試_第2頁
【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試_第3頁
【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試_第4頁
【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試_第5頁
已閱讀5頁,還剩14頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

【移動應(yīng)用開發(fā)技術(shù)】C#如何實(shí)現(xiàn)微信小店商品管理接口的封裝和測試

/upload/information/20201208/260/13052.jpg/upload/information/20201208/260/13053.jpg#region

商品信息

///

<summary>

///

創(chuàng)建商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="merchantJson">商品對象</param>

///

<returns></returns>

AddMerchantResult

AddMerchant(string

accessToken,

MerchantJson

merchantJson);

///

<summary>

///

刪除商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="productId">商品ID</param>

///

<returns></returns>

CommonResult

DeleteMerchant(string

accessToken,

string

productId);

///

<summary>

///

修改商品

///

product_id表示要更新的商品的ID,其他字段說明請參考增加商品接口。

///

從未上架的商品所有信息均可修改,否則商品的名稱(name)、商品分類(category)、商品屬性(property)這三個(gè)字段不可修改。

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="merchantJson">修改商品的信息</param>

///

<returns></returns>

CommonResult

UpdateMerchant(string

accessToken,

MerchantJson

merchantJson);

///

<summary>

///

根據(jù)ID查詢商品信息,如果成功返回MerchantJson信息,否則返回null

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="productId">商品的Id</param>

///

<returns></returns>

MerchantJson

GetMerchant(string

accessToken,

string

productId);

///

<summary>

///

獲取指定狀態(tài)的所有商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="status">商品狀態(tài)(0-全部,

1-上架,

2-下架)</param>

///

<returns></returns>

List<MerchantJson>

GetMerchantByStatus(string

accessToken,

int

status);

///

<summary>

///

商品上下架

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="status">商品上下架標(biāo)識(0-下架,

1-上架)</param>

///

<returns></returns>

CommonResult

UpdateMerchantStatus(string

accessToken,

string

productId,

int

status);

#endregion/upload/information/20201208/260/13054.jpg#region

商品分類及屬性

///

<summary>

///

獲取指定分類的所有子分類

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="cateId">大分類ID(根節(jié)點(diǎn)分類id為1)</param>

///

<returns></returns>

List<SubCategory>

GetSub(string

accessToken,

int

cate_id);

///

<summary>

///

獲取指定子分類的所有SKU

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="cateId">商品子分類ID</param>

///

<returns></returns>

List<SubCategorySku>

GetSku(string

accessToken,

int

cate_id);

///

<summary>

///

獲取指定分類的所有屬性

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="cateId">分類ID</param>

///

<returns></returns>

List<SubCategoryProperty>

GetProperty(string

accessToken,

int

cate_id);

#endregion2、商品管理接口的實(shí)現(xiàn)///

<summary>

///

創(chuàng)建商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="merchantJson">商品對象</param>

///

<returns></returns>

public

AddMerchantResult

AddMerchant(string

accessToken,

MerchantJson

merchantJson)

{

var

url

=

string.Format("/merchant/create?access_token={0}",

accessToken);

string

postData

=

merchantJson.ToJson();

return

JsonHelper<AddMerchantResult>.ConvertJson(url,

postData);

}///

<summary>

///

微信返回Json結(jié)果的錯(cuò)誤數(shù)據(jù)

///

</summary>

public

class

ErrorJsonResult

{

///

<summary>

///

返回代碼

///

</summary>

public

ReturnCode

errcode

{

get;

set;

}

///

<summary>

///

錯(cuò)誤消息

///

</summary>

public

string

errmsg

{

get;

set;

}

}///

<summary>

///

刪除商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="productId">商品ID</param>

///

<returns></returns>

public

CommonResult

DeleteMerchant(string

accessToken,

string

productId)

{

var

url

=

string.Format("/merchant/del?access_token={0}",

accessToken);

var

data

=

new

{

product_id

=

productId

};

string

postData

=

data.ToJson();

return

Helper.GetExecuteResult(url,

postData);

}

///

<summary>

///

修改商品

///

product_id表示要更新的商品的ID,其他字段說明請參考增加商品接口。

///

從未上架的商品所有信息均可修改,否則商品的名稱(name)、商品分類(category)、商品屬性(property)這三個(gè)字段不可修改。

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="merchantJson">修改商品的信息</param>

///

<returns></returns>

public

CommonResult

UpdateMerchant(string

accessToken,

MerchantJson

merchantJson)

{

var

url

=

string.Format("/merchant/update?access_token={0}",

accessToken);

string

postData

=

merchantJson.ToJson();

return

Helper.GetExecuteResult(url,

postData);

}/upload/information/20201208/260/13055.jpg

///

<summary>

///

根據(jù)ID查詢商品信息,如果成功返回MerchantJson信息,否則返回null

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="productId">商品的Id</param>

///

<returns></returns>

public

MerchantJson

GetMerchant(string

accessToken,

string

productId)

{

var

url

=

string.Format("/{0}",

accessToken);

var

data

=

new

{

product_id

=

productId

};

string

postData

=

data.ToJson();

MerchantJson

merchant

=

null;

GetMerchantResult

result

=

JsonHelper<GetMerchantResult>.ConvertJson(url,

postData);

if

(result

!=

null)

{

merchant

=

duct_info;

}

return

merchant;

}///

<summary>

///

獲取指定狀態(tài)的所有商品

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="status">商品狀態(tài)(0-全部,

1-上架,

2-下架)</param>

///

<returns></returns>

public

List<MerchantJson>

GetMerchantByStatus(string

accessToken,

int

status)

{

var

url

=

string.Format("/merchant/getbystatus?access_token={0}",

accessToken);

var

data

=

new

{

status

=

status

};

string

postData

=

data.ToJson();

List<MerchantJson>

list

=

new

List<MerchantJson>();

GetMerchantByStatus

result

=

JsonHelper<GetMerchantByStatus>.ConvertJson(url,

postData);

if

(result

!=

null)

{

list

=

ducts_info;

}

return

list;

}///

<summary>

///

獲取指定分類的所有子分類

///

</summary>

///

<param

name="accessToken">調(diào)用接口憑證</param>

///

<param

name="cateId">大分類ID(根節(jié)點(diǎn)分類id為1)</param>

///

<returns></returns>

public

List<SubCategory>

GetSub(string

accessToken,

int

cate_id)

{

var

url

=

string.Format("/merchant/category/getsub?access_token={0}",

accessToken);

var

data

=

new

{

cate_id

=

cate_id

};

string

postData

=

data.ToJson();

List<SubCategory>

list

=

new

List<SubCategory>();

GetSubResult

result

=

JsonHelper<GetSubResult>.ConvertJson(url,

postData);

if(result

!=

null)

{

list

=

result.cate_list;

}

return

list;

}3、商品管理接口的測試/upload/information/20201208/260/13056.jpgprivate

void

btnMerchant_Click(object

sender,

EventArgs

e)

{

//商品管理

IMerchantApi

api

=

new

MerchantApi();

//獲取所有商品信息

Console.WriteLine("獲取所有商品信息");

List<MerchantJson>

list

=

api.GetMerchantByStatus(token,

0);

foreach(MerchantJson

json

in

list)

{

Console.WriteLine(json.ToJson());

Console.WriteLine();

}

//更新商品狀態(tài)

Console.WriteLine("更新商品狀態(tài)");

foreach

(MerchantJson

json

in

list)

{

CommonResult

result

=

api.UpdateMerchantStatus(token,

duct_id,

1);

Console.WriteLine("商品ID:{0},商品名稱:{1},

操作:{2}",

duct_id,

duct_,

result.Success

?

"成功"

:

"失敗");

}

Thread.Sleep(1000);

//根據(jù)商品ID獲取商品信息

Console.WriteLine("根據(jù)商品ID獲取商品信息");

foreach

(MerchantJson

json

in

list)

{

MerchantJson

getJson

=

api.GetMerchant(token,

duct_id);

if(json

!=

null)

{

Console.WriteLine("商品ID:{0},商品名稱:{1}",

getJduct_id,

getJduct_);

}

}

}{

"product_id":

"pSiLnt6FYDuFtrRRPMlkdKbye-rE",

"product_base":

{

"category_id":

[

"537103312"

],

"property":

[

{

"id":

"類型",

"vid":

"軟件產(chǎn)品設(shè)計(jì)"

}

],

"name":

"代碼生成工具Database2Sharp",

"sku_info":

[],

"main_img":

"/mmbiz/mLqH9gr11Gyb2sgiaelcsxYtQENGePp0Rb3AZKbjkicnKTUNBrEdo7Dyic97ar46SoAfKRB5x2R94bDUdNpgqiaZzA/0",

"img":

[

"/mmbiz/mLqH9gr11Gyb2sgiaelcsxYtQENGePp0RiaheJmVXm7tbvTYUQV7OF3DgfGiaQVMh4WbeEcGDOQQiajQXGKK9tfoeA/0"

],

"detail":

[],

"buy_limit":

0,

"detail_html":

""

},

"sku_list":

[

{

"sku_id":

"",

"ori_price":

100000,

"price":

50000,

"icon_url":

"",

"quantity":

1100,

"product_code":

""

}

],

"attrext":

{

"location":

{

"country":

"中國",

"province":

"廣東",

"city":

"廣州",

"address":

""

},

"isPostFree":

1,

"isHasReceipt":

0,

"isUnderGuaranty":

0,

"isSupportReplace":

0

},

"delivery_info":

{

"delivery_type":

0,

"template_id":

175807970,

"express":

[

{

"id":

10000027,

"price":

0

},

{

"id":

10000028,

"price":

0

},

{

"id":

10000029,

"price":

0

}

]

},

"status":

1

}/upload/information/20201208/260/13058.jpgprivate

void

btnMerchantEdit_Click(object

sender,

EventArgs

e)

{

IMerchantApi

api

=

new

MerchantApi();

string

img1

=

"/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0";

string

img2

=

"/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ul1UcLcwxrFdwTKYhH9Q5YZoCfX4Ncx655ZK6ibnlibCCErbKQtReySaVA/0";

string

img3

=

"/mmbiz/4whpV1VZl28bJj62XgfHPibY3ORKicN1oJ4CcoIr4BMbfA8LqyyjzOZzqrOGz3f5KWq1QGP3fo6TOTSYD3TBQjuw/0";

//商品增刪改處理

MerchantJson

merchant

=

new

MerchantJson();

duct_base

=

new

Merchant_base();

duct_

=

"測試產(chǎn)品";

duct_base.category_id.Add("537074298");

duct_base.img

=

new

List<string>()

{

img1,

img2,

img3

};

duct_base.main_img

=

img1;

duct_base.detail.AddRange(new

List<MerchantDetail>()

{

new

MerchantDetail()

{

text

=

"test

first"

},

new

MerchantDetail()

{

img

=

img2

},

new

MerchantDetail()

{

text

=

"test

again"

}

});

duct_perty.AddRange(new

List<MerchantProperty>(){

new

MerchantProperty

{

id=

"1075741879",

vid="1079749967"

},

new

MerchantProperty{

id=

"1075754127",

vid=

"1079795198"

},

new

MerchantProperty(){

id=

"1075777334",

vid=

"1079837440"

}

});

duct_base.sku_info.AddRange(new

List<MerchantSku>(){

new

MerchantSku{

id=

"1075741873",

vid

=

new

List<string>()

{

"1079742386",

"1079742363"

}

}

});

duct_base.buy_limit

=

10;

//duct_base.detail_html

=

"<div

class=\"item_pic_wrp\"

style=\"margin-bottom:8px;font-size:0;\"><img

class=\"item_pic\"

style=\"width:100%;\"

alt=\"\"

src=\"/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0\"

></div><p

style=\"margin-bottom:11px;margin-top:11px;\">test</p><div

class=\"item_pic_wrp\"

style=\"margin-bottom:8px;font-size:0;\"><img

class=\"item_pic\"

style=\"width:100%;\"

alt=\"\"

src=\"/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ul1UcLcwxrFdwTKYhH9Q5YZoCfX4Ncx655ZK6ibnlibCCErbKQtReySaVA/0\"

></div><p

style=\"margin-bottom:11px;margin-top:11px;\">test

again</p>";

merchant.sku_list.AddRange(new

List<MerchantSku_list>()

{

new

MerchantSku_list(){

sku_id="1075741873:1079742386",

price=30,

icon_url="/mmbiz/4whpV1VZl2iccsvYbHvnphkyGtnvjD3ulEKogfsiaua49pvLfUS8Ym0GSYjViaLic0FD3vN0V8PILcibEGb2fPfEOmw/0",

quantity=800,

product_code="testing",

ori_price=9000000

},

new

MerchantSku_list(){

sku_id="1075741873:1079742363",

price=30,

icon_url="/mmbiz/4whpV1VZl28bJj62XgfHPibY3ORKicN1oJ4CcoIr4BMbfA8LqyyjzOZzqrOGz3f5KWq1QGP3fo6TOTSYD3TBQjuw/0",

quantity=800,

product_code="testingtesting",

ori_price=9000000

}

});

merchant.attrext

=

new

MerchantAttrext()

{

location

=

new

MerchantLocation()

{

country

=

"中國",

province

=

"廣東省",

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論