Payment development (6) receiving address sharing interface and payment interface development. Payment development (6) receiving address sharing interface, payment interface development keyword: payment receiving address sharing author: Fang times studio original: www. cnblogs. comtxw1958 payment development (6) receiving address sharing interface and payment interface development
Keywords: payment and receipt address sharing
Author: Fang times Studio
Original article: http://www.cnblogs.com/txw1958/p/weixin-editAddress.html
This article describes the development process of the shipping address sharing interface under payment.
I. INTRODUCTION
Shipping address sharing means that after you open a webpage in your browser and enter the address, you can quickly select or add or edit the address without entering it. This address is a user attribute and can be shared on the webpage of each merchant. Native controls are supported to enter the address, and the address data is transmitted to the merchant.
Address sharing is implemented based on JavaScript APIs and can only be used in built-in browsers. other browser calls are invalid. At the same time, Version 5.0 is required. we recommend that you use the user agent to determine the current version number and then call the address interface. Take the iPhone version as an example. you can use useragent to obtain the following sample information: "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 indicates the version number installed by the user. the merchant can determine whether the version number is higher than or equal to 5.0.
Address format
Data fields used for address sharing include:
- Recipient name
- Level 3, region, province, city
- Detailed address
- Zip Code
- Contact number
The region corresponds to the third-level geocode of the national standard, for example, "Guangdong province-Guangzhou-Tianhe District", and the corresponding zip code is 510630. Http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html for details
II. OAuth2.0 authorization
Before obtaining the shipping address, you must call the logon authorization interface to obtain the OAuth2.0 Access Token. Therefore, an authorization is required. the confirmation box is not displayed for this authorization.
The essence is that
http://www.fangbei.org/wxpay/js_api_call.php
Jump
https://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
To obtain the code parameter, and obtain the authorized access_token and openid based on the code. this access token will be used for the shipping address sharing interface.
For details about the implementation process, refer to OAuth2.0 webpage authorization on the public platform development (71 ).
II. obtain random strings
The method for generating random strings is as follows:
III. generate a signature
The fields involved in the addrSign signature include: appId, url (webpage url that calls JavaScript APIs), timestamp, noncestr, and accessToken.
After all parameters to be signed are sorted in ascending order (lexicographically) according to the field name ASCII code, the format of the URL Key-value pair is used (that is, key1 = value1 & key2 = value2 ...) Concatenate the string into string1.
Note that all parameter names are lowercase characters in the signature process. for example, if appId is sorted, the string is appid;
Use string1 as a signature algorithm. both field names and field values use original values without URL escaping. The specific signature algorithm is addrSign = SHA1 (string1 ). The following is an example of generating an addrSign:
appId=wx17ef1eaef46752cburl=http://open.weixin.qq.com/timeStamp=1384841012nonceStr=123456accessToken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA
I: after sorting key-value pairs in process a, string1 is:
accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=123456×tamp=1384841012&url=http://open.weixin.qq.com/?code=CODE&state=STATE
Ii: After the signature of Process B, you can obtain:
addrSign=SHA1(accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=123456×tamp=1384841012&url=http://open.weixin.qq.com/?code=CODE&state=STATE)=ca604c740945587544a9cc25e58dd090f200e6fb
The implementation code is as follows:
4. obtain the shipping address
Edit and obtain the editAddress interface of the user's shipping address, which is called at the front-end of the webpage.
Parameter list:
Parameters |
Required |
Description |
AppId |
Yes |
Public Account appID |
Scope |
Yes |
Enter "jsapi_address" to obtain the edit address permission. |
SignType |
Yes |
Signature Method. Currently, only SHA1 is supported. |
AddrSign |
Yes |
Signature. each parameter is used for signature generation. |
TimeStamp |
Yes |
Timestamp |
NonceStr |
Yes |
Random string |
The call method is as follows:
Parameter return:
Return value |
Description |
Err_msg |
Edit_address: OK. the shipping address is successfully edited. |
Edit_address: fail failed to get and edit the shipping address. |
Username |
Recipient name |
TelNumber |
Recipient's phone number |
AddressPostalCode |
Zip Code |
ProviceFirstStageName |
National standard receiving Address Level 1 Address |
AddressCitySecondStageName |
Second-level address of national standard receiving address |
AddressCountiesThirdStageName |
National standard receiving Address Level 3 address |
AddressDetailInfo |
Detailed shipping address information |
NationalCode |
Country code of the shipping address |
V. example
Inventory (6) shipping address sharing interface, payment interface development Keywords: payment shipping address sharing author: Fang times studio Original text: http://www.cnblogs.com/txw1958...