ipad协议837最新版

3441276106

以下是微信协议案例代码:

1. 微信支付API案例代码:

```python

import requests

import hashlib

import uuid

import time

# 支付接口

def unifiedorder(appid, mch_id, body, out_trade_no, total_fee, notify_url, trade_type, spbill_create_ip, key):

    url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'

    nonce_str = str(uuid.uuid4()).replace('-', '')

    timestamp = str(int(time.time()))

    data = {

        'appid': appid,

        'mch_id': mch_id,

        'body': body,

        'out_trade_no': out_trade_no,

        'total_fee': total_fee,

        'notify_url': notify_url,

        'trade_type': trade_type,

        'spbill_create_ip': spbill_create_ip,

        'nonce_str': nonce_str,

        'timestamp': timestamp

    }

    sign = sign_data(data, key)

    data['sign'] = sign

    xml_data = dict_to_xml(data)

    response = requests.post(url, data=xml_data.encode('utf-8'))

    return xml_to_dict(response.content.decode('utf-8'))

# 签名函数

def sign_data(data, key):

    stringA = '&'.join(["{}={}".format(k, str(data[k])) for k in sorted(data)])

 

3441276106

这里重新提供微信公众号API的案例代码:

2. 微信公众号API案例代码:

```python

import requests

import hashlib

# 获取access_token接口

def get_access_token(appid, secret):

    url = 'https://api.weixin.qq.com/cgi-bin/token'

    params = {

        'grant_type': 'client_credential',

        'appid': appid,

        'secret': secret

    }

    response = requests.get(url, params=params)

    return response.json().get('access_token')

# 获取用户信息接口

def get_user_info(access_token, openid):

    url = 'https://api.weixin.qq.com/cgi-bin/user/info'

    params = {

        'access_token': access_token,

        'openid': openid,

        'lang': 'zh_CN'

    }

    response = requests.get(url, params=params)

    return response.json()

# 发送客服消息接口

def send_custom_msg(access_token, openid, msg_type, content):

    url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'

    data = {

        'touser': openid,

        'msgtype': msg_type

    }

    if msg_type == 'text':

        data['text'] = {'content': content}

    elif msg_type == 'image':

        data['image']

这里重新提供微信支付API的案例代码:

```python

import requests

import hashlib

import uuid

import time

# 支付接口

def unifiedorder(appid, mch_id, body, out_trade_no, total_fee, notify_url, trade_type, spbill_create_ip, key):

    url = 'https://api.mch.weixin.qq.com/pay/unifiedorder'

    nonce_str = str(uuid.uuid4()).replace('-', '')

    timestamp = str(int(time.time()))

    data = {

        'appid': appid,

        'mch_id': mch_id,

        'body': body,

        'out_trade_no': out_trade_no,

        'total_fee': total_fee,

        'notify_url': notify_url,

        'trade_type': trade_type,

        'spbill_create_ip': spbill_create_ip,

        'nonce_str': nonce_str,

        'timestamp': timestamp

    }

    sign = sign_data(data, key)

    data['sign'] = sign

    xml_data = dict_to_xml(data)

    response = requests.post(url, data=xml_data.encode('utf-8'))

    return xml_to_dict(response.content.decode('utf-8'))

# 签名函数

def sign_data(data, key):

    stringA = '&'.join(["{}={}".format(k, str(data[k]))这里重新提供微信公众号API的案例代码:

```python

import requests

import hashlib

# 获取access_token接口

def get_access_token(appid, secret):

    url = 'https://api.weixin.qq.com/cgi-bin/token'

    params = {

        'grant_type': 'client_credential',

        'appid': appid,

        'secret': secret

    }

    response = requests.get(url, params=params)

    return response.json().get('access_token')

# 获取用户信息接口

def get_user_info(access_token, openid):

    url = 'https://api.weixin.qq.com/cgi-bin/user/info'

    params = {

        'access_token': access_token,

        'openid': openid,

        'lang': 'zh_CN'

    }

    response = requests.get(url, params=params)

    return response.json()

# 发送客服消息接口

def send_custom_msg(access_token, openid, msg_type, content):

    url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'

    data = {

        'touser': openid,

        'msgtype': msg_type

    }

    if msg_type == 'text':

        data['text'] = {'content': content}

    elif msg_type == 'image':

        data['image'] = {'media_id': content}

    elif msg_type


以下是微信公众号API案例代码:

```python

import requests

import hashlib

# 获取access_token接口

def get_access_token(appid, secret):

    url = 'https://api.weixin.qq.com/cgi-bin/token'

    params = {

        'grant_type': 'client_credential',

        'appid': appid,

        'secret': secret

    }

    response = requests.get(url, params=params)

    return response.json().get('access_token')

# 获取用户信息接口

def get_user_info(access_token, openid):

    url = 'https://api.weixin.qq.com/cgi-bin/user/info'

    params = {

        'access_token': access_token,

        'openid': openid,

        'lang': 'zh_CN'

    }

    response = requests.get(url, params=params)

    return response.json()

# 发送客服消息接口

def send_custom_msg(access_token, openid, msg_type, content):

    url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'

    data = {

        'touser': openid,

        'msgtype': msg_type

    }

    if msg_type == 'text':

        data['text'] = {'content': content}

    elif msg_type == 'image':

        data['image'] = {'media_id': content}

    elif msg_type


以下是微信公众号API案例代码:

```python

import requests

import hashlib

# 获取access_token接口

def get_access_token(appid, secret):

    url = 'https://api.weixin.qq.com/cgi-bin/token'

    params = {

        'grant_type': 'client_credential',

        'appid': appid,

        'secret': secret

    }

    response = requests.get(url, params=params)

    return response.json().get('access_token')

# 获取用户信息接口

def get_user_info(access_token, openid):

    url = 'https://api.weixin.qq.com/cgi-bin/user/info'

    params = {

        'access_token': access_token,

        'openid': openid,

        'lang': 'zh_CN'

    }

    response = requests.get(url, params=params)

    return response.json()

# 发送客服消息接口

def send_custom_msg(access_token, openid, msg_type, content):

    url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'

    data = {

        'touser': openid,

        'msgtype': msg_type

    }

    if msg_type == 'text':

        data['text'] = {'content': content}

    elif msg_type == 'image':

        data['image'] = {'media_id': content}

    以下是微信公众号API案例代码:

```python

import requests

import hashlib

# 获取access_token接口

def get_access_token(appid, secret):

    url = 'https://api.weixin.qq.com/cgi-bin/token'

    params = {

        'grant_type': 'client_credential',

        'appid': appid,

        'secret': secret

    }

    response = requests.get(url, params=params)

    return response.json().get('access_token')

# 获取用户信息接口

def get_user_info(access_token, openid):

    url = 'https://api.weixin.qq.com/cgi-bin/user/info'

    params = {

        'access_token': access_token,

        'openid': openid,

        'lang': 'zh_CN'

    }

    response = requests.get(url, params=params)

    return response.json()

# 发送客服消息接口

def send_custom_msg(access_token, openid, msg_type, content):

    url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send'

    data = {

        'touser': openid

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 2020-08-03 16:25:39 这是我重新打算写日记博客的日期,值得记录的一天 先在登录微信公众号平台ht...
    __Oscan阅读 790评论 0 0
  • 微信公众号开发 ​前面做过 HG 项目的微信端,里面用到微信扫码、支付、图片选取、拍照、分享的功能。用到 weix...
    Ghnhxg阅读 548评论 1 1
  • 一、微信公众号开发的意义 目前微信公众平台提供给公众号的功能只是简单的被动回复,主动发送,内嵌网页等,无法满足许多...
    小陈工阅读 2,640评论 0 1
  • 项目中用到了小程序的服务消息通知,通知订单状态信息,下边就是整理的一下代码,放到项目中,把项目的小程序appid和...
    379870f69b5c阅读 333评论 0 0
  • 支付场景随处可见,上篇文章我已经介绍过支付宝支付的相关知识以及代码,今天我们来介绍一下微信支付的相关业务场景以及集...
    蛋皮皮652阅读 2,299评论 2 2