WeChat payment development (6) Receiving address sharing interface, WeChat payment interface development_PHP tutorial

WBOY
Release: 2016-07-12 08:55:56
Original
1249 people have browsed it

WeChat payment development (6) delivery address sharing interface, WeChat payment interface development

Keywords: WeChat payment delivery address sharing
Author: Fangbei Studio
Original text: http://www.cnblogs.com/txw1958/p/weixin-editAddress.html

This article introduces the development process of the delivery address sharing interface under WeChat payment.

1. Introduction

WeChat delivery address sharing means that users open a webpage in the WeChat browser and fill in the address. They can then quickly select without filling in the address, and can also add and edit it. This address is a user attribute and can be shared on the web pages of various merchants. Support native controls to fill in addresses, and the address data will be passed to the merchant.

Address sharing is based on the WeChat JavaScript API and can only be used in the WeChat built-in browser. Calls from other browsers are invalid. At the same time, WeChat version 5.0 is required to support it. It is recommended to use the user agent to determine the user's current version number before calling the address interface. Taking the iPhone version as an example, you can obtain the following WeChat version example information through useragent: "Mozilla/5.0(iphone;CPU iphone OS 5_1_1 like Mac OS For the version number of WeChat installed by the user, the merchant can determine whether the version number is higher than or equal to 5.0.

Address format
The data fields used for WeChat address sharing include:

  • Consignee’s name
  • Regions, provinces and municipalities at three levels
  • Detailed address
  • Postcode
  • Contact number

Among them, the region corresponds to the national standard three-level area code, such as "Guangdong Province-Guangzhou City-Tianhe District", and the corresponding postal code is 510630. Reference link for details: http://www.stats.gov.cn/tjsj/tjbz/xzqhdm/201401/t20140116_501070.html

2. OAuth2.0 authorization

Before obtaining the delivery address, you need to call the login authorization interface to obtain an OAuth2.0 Access Token. Therefore, authorization needs to be done once, and the confirmation box will not pop up for this authorization.
The essence is that when the user accesses

http:<span>//</span><span>www.fangbei.org/wxpay/js_api_call.php</span>
Copy after login
Jump to

when

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>
Copy after login

Use this 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 delivery address sharing interface.

For the detailed process of its implementation, please refer to WeChat Public Platform Development (71) OAuth2.0 Web Authorization

2. Get random string

The method to generate a random string is as follows

3. Generate signature

Fields participating in addrSign signature include: appId, url (webpage URL calling JavaScript API), timestamp, noncestr, accessToken
After sorting all the parameters to be signed according to the ASCII code of the field name from small to large (lexicographic order) , use the URL key-value pair format (i.e. key1=value1&key2=value2...) to concatenate it into a string string1.
It should be noted here that all parameter names during the signature process are in lowercase characters. For example, the appId string after sorting is appid;
For the signature algorithm on string1, the field names and field values ​​​​use the original values ​​and do not proceed. URL escaping. The specific signature algorithm is addrSign = SHA1(string1). The specific example of generating addrSign is given here:

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
Copy after login

i: After sorting the key-value pairs through the a process, string1 is obtained:

accesstoken=OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmgh5FRA&appid=wx17ef1eaef46752cb&noncestr=<span>123456</span>&timestamp=<span>1384841012</span>&url=http:<span>//</span><span>open.weixin.qq.com/?code=CODE&state=STATE</span>
Copy after login

ii: After signing through process b, you can get:

addrSign=SHA1(accesstoken=<span>OezXcEiiBSKSxW0eoylIeBFk1b8VbNtfWALJ5g6aMgZHaqZwK4euEskSn78Qd5pLsfQtuMdgmhajVM5QDm24W8X3tJ18kz5mhmkUcI3RoLm7qGgh1cEnCHejWQo8s5L3VvsFAdawhFxUuLmg
h5FRA</span>&appid=wx17ef1eaef46752cb&noncestr=<span>123456</span>&timestamp=<span>1384841012</span>&url=http:<span>//</span><span>open.weixin.qq.com/?code=CODE&state=STATE)=ca604c740945587544a9cc25e58dd090f200e6fb</span>
Copy after login

The implementation code is as follows

4. Obtain the delivery address

Edit and obtain the user's delivery address editAddress interface, which is called on the front end of the web page.
Parameter list:

参数 必填 说明
appId 公众号appID
scope 填写“jsapi_address”,获得编辑地址权限
signType 签名方式,目前仅支持SHA1
addrSign 签名,由各参数一起参与签名生成
timeStamp 时间戳
nonceStr 随机字符串

The calling method is as follows

Parameter return:

返回值 说明
err_msg edit_address:ok获取编辑收货地址成功
edit_address:fail获取编辑收货地址失败
username 收货人姓名
telNumber 收货人电话
addressPostalCode 邮编
proviceFirstStageName 国标收货地址第一级地址
addressCitySecondStageName 国标收货地址第二级地址
addressCountiesThirdStageName 国标收货地址第三级地址
addressDetailInfo 详细收货地址信息
nationalCode 收货地址国家码

5. Example

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1114989.htmlTechArticleWeChat payment development (6) Receiving address sharing interface, WeChat payment interface development keywords: WeChat payment receiving address Shared author: Fangbei Studio Original text: http://www.cnblogs.com/txw1958/...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template