微信支付開發(fā)(6) 收貨地址共享接口,微信支付接口開發(fā)
Jun 13, 2016 am 08:43 AM微信支付開發(fā)(6) 收貨地址共享接口,微信支付接口開發(fā)
關(guān)鍵字:微信支付?收貨地址共享
作者:方倍工作室
原文:?http://www.cnblogs.com/txw1958/p/weixin-editAddress.html
?
本文介紹微信支付下的收貨地址共享接口的開發(fā)過程。
一. 簡介
微信收貨地址共享,是指用戶在微信瀏覽器內(nèi)打開網(wǎng)頁,填寫過地址后,后續(xù)可以免填寫支持快速選擇,也可增加和編輯。此地址為用戶屬性,可在各商戶的網(wǎng)頁中共享使用。支持原生控件填寫地址,地址數(shù)據(jù)會傳遞到商戶。
地址共享是基于微信JavaScript API 實現(xiàn),只能在微信內(nèi)置瀏覽器中使用,其他瀏覽器調(diào)用無效。同時,需要微信5.0 版本才能支持,建議通過user agent 來確定用戶當前的版本號后再調(diào)用地址接口。以iPhone 版本為例,可以通過useragent可獲取如下微信版本示例信息:"Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS X)AppleWebKit/534.46(KHTML,like Geocko) Mobile/9B206MicroMessenger/5.0"其中5.0 為用戶安裝的微信版本號,商戶可以判定版本號是否高于或者等于5.0。
地址格式
微信地址共享使用的數(shù)據(jù)字段包括:
- 收貨人姓名
- 地區(qū),省市區(qū)三級
- 詳細地址
- 郵編
- 聯(lián)系電話
其中,地區(qū)對應(yīng)是國標三級地區(qū)碼,如“廣東省-廣州市-天河區(qū)”,對應(yīng)的郵編是是510630。詳情參考鏈接:http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html
?
二. OAuth2.0授權(quán)
獲取收貨地址之前前需要調(diào)用 登錄授權(quán)接口獲取到一次OAuth2.0的Access Token 。所以需要做一次授權(quán),這次授權(quán)是不彈出確認框的。
其實質(zhì)就是在用戶訪問
http:<span>//</span><span>www.fangbei.org/wxpay/js_api_call.php</span>
時跳轉(zhuǎn)到
https:<span>//</span><span>open.weixin.qq.com/connect/oauth2/authorize?appid=wx8888888888888888&redirect_uri=http://www.fangbei.org/wxpay/js_api_call.php&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect</span>
以此來獲得code參數(shù),并根據(jù)code來獲得授權(quán)access_token及openid,這個access token將用于收貨地址共享接口。
其實現(xiàn)的詳細流程可參考 微信公眾平臺開發(fā)(71)OAuth2.0網(wǎng)頁授權(quán)
二、獲取隨機字符串
生成隨機字符串的方法如下
三、生成簽名
參與addrSign 簽名的字段包括:appId、url(調(diào)用JavaScript API的網(wǎng)頁url)、timestamp、noncestr、accessToken
對所有待簽名參數(shù)按照字段名的ASCII 碼從小到大排序(字典序)后,使用URL 鍵值對的格式(即key1=value1&key2=value2…)拼接成字符串string1。
這里需要注意的是簽名過程中所有參數(shù)名均為小寫字符,例如appId 在排序后字符串則為appid;
對string1作簽名算法,字段名和字段值都采用原始值,不進行URL 轉(zhuǎn)義。具體簽名算法為addrSign = SHA1(string1)。這里給出生成addrSign 的具體示例如下:
appId=<span>wx17ef1eaef46752cb url</span>=http:<span>//</span><span>open.weixin.qq.com/</span> timeStamp=<span>1384841012</span><span> nonceStr</span>=<span>123456</span><span> accessToken</span>=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA
i:經(jīng)過a過程鍵值對排序后得到string1 為:
accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=<span>123456</span>×tamp=<span>1384841012</span>&url=http:<span>//</span><span>open.weixin.qq.com/?code=CODE&state=STATE</span>
ii:經(jīng)過b過程簽名后可得到:
addrSign=SHA1(accesstoken=<span>OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmg h5FRA</span>&appid=wx17ef1eaef46752cb&noncestr=<span>123456</span>×tamp=<span>1384841012</span>&url=http:<span>//</span><span>open.weixin.qq.com/?code=CODE&state=STATE)=ca604c740945587544a9cc25e58dd090f200e6fb</span>
實現(xiàn)代碼如下
?
四、獲得收貨地址
編輯并獲取用戶收貨地址editAddress接口,在網(wǎng)頁前端調(diào)用。
參數(shù)列表:
參數(shù) | 必填 | 說明 |
---|---|---|
appId | 是 | 公眾號appID |
scope | 是 | 填寫“jsapi_address”,獲得編輯地址權(quán)限 |
signType | 是 | 簽名方式,目前僅支持SHA1 |
addrSign | 是 | 簽名,由各參數(shù)一起參與簽名生成 |
timeStamp | 是 | 時間戳 |
nonceStr | 是 | 隨機字符串 |
調(diào)用方法如下
參數(shù)返回:
返回值 | 說明 |
---|---|
err_msg | edit_address:ok獲取編輯收貨地址成功 |
edit_address:fail獲取編輯收貨地址失敗 | |
username | 收貨人姓名 |
telNumber | 收貨人電話 |
addressPostalCode | 郵編 |
proviceFirstStageName | 國標收貨地址第一級地址 |
addressCitySecondStageName | 國標收貨地址第二級地址 |
addressCountiesThirdStageName | 國標收貨地址第三級地址 |
addressDetailInfo | 詳細收貨地址信息 |
nationalCode | 收貨地址國家碼 |
?
?
五、示例
????
?

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Nice Comics, an immersive reading experience platform dedicated to creating for comic lovers, brings together a large number of high-quality comic resources at home and abroad. It is not only a comic reading platform, but also a community that connects comic artists and readers and shares comic culture. Through simple and intuitive interface design and powerful search functions, NES Comics allows you to easily find your favorite works and enjoy a smooth and comfortable reading experience. Say goodbye to the long waiting and tedious operations, enter the world of Nice comics immediately and start your comic journey!

Frogman Comics has become the first choice for many comic lovers with its rich and diverse comic resources and convenient and smooth online reading experience. It is like a vibrant pond, with fresh and interesting stories constantly emerging, waiting for you to discover and explore. Frog Man comics cover a variety of subjects, from passionate adventures to sweet love, from fantasy and science fiction to suspense reasoning, no matter which genre you like, you can find your favorite works here. Its simple and intuitive interface design allows you to easily get started, quickly find the comics you want to read, and immerse yourself in the exciting comic world.

Android mobile phone users can download and install Huobi/Huobi App through the following steps: 1. Ensure the network is stable and the storage space is sufficient; 2. Download the App through Huobi/Huobi official website, use the browser to access the official website and click the download link or scan the QR code, or search and download through third-party application stores such as AppTreasure and Huawei App Market, and you can also obtain the installation package through friends' sharing; 3. Find the downloaded .apk file, enable the "Unknown Source App" installation permission, follow the prompts to complete the installation, etc.

Yes, but there are restrictions. ① You can log in to the same account on both iPhone and Android phones, but logging in to the latest device will cause the earliest session to be offline; ② You can log in at the same time on the mobile phone and the computer desktop, but the functions are not synchronized; ③ Although using third-party tools or dual-app functions can enable logging in between two mobile phones, it is unofficially supported and may violate regulations; ④ Alternative solutions include using web version/desktop version to match the main phone, or transferring chat records through cloud backup and file tools. Some Android machines can also use "dual applications" to run two account instances.

The steps for downloading and installing the Yiou Exchange (OKX) Android client are as follows: 1. Download the official genuine installation package through the official website www.okx.com or the official QR code; 2. Find the downloaded .apk file in the mobile phone file manager and enable the "Unknown Source" installation permission; 3. Click the installation package to install, and after the installation is completed, open the APP and register or log in to the account; 4. Set up complex passwords, enable secondary verification, regularly change passwords, properly keep private keys and mnemonics, and beware of phishing websites to ensure account security.

Huobi App is the world's leading digital asset trading platform, providing safe, convenient and professional trading services. As a platform trusted by millions of users around the world, Huobi App supports transactions of various mainstream digital currencies such as Bitcoin and Ethereum, and provides a variety of trading tools such as spot, contracts, and leverage. The latest version of v10.52.0 optimizes the trading engine, improves speed and stability, adds a variety of new trading functions, and strengthens security protection.

In Go, an interface is a type that defines behavior without specifying implementation. An interface consists of method signatures, and any type that implements these methods automatically satisfy the interface. For example, if you define a Speaker interface that contains the Speak() method, all types that implement the method can be considered Speaker. Interfaces are suitable for writing common functions, abstract implementation details, and using mock objects in testing. Defining an interface uses the interface keyword and lists method signatures, without explicitly declaring the type to implement the interface. Common use cases include logs, formatting, abstractions of different databases or services, and notification systems. For example, both Dog and Robot types can implement Speak methods and pass them to the same Anno

HTX (formerly Huobi) launches the latest mobile app, supports Apple and Android systems, and provides real-time market trends, transactions, contract financial management and other functions. Users can download and install them through the official website, TestFlight or the app store.
