应用场景
二维码收款
接口
官方文档:https://doc.open.alipay.com/doc2/apiDetail.htm?spm=a219a.7395905.0.0.O4mxCP&docType=4&apiId=862
过程
通过调用接口得到官方的二维码地址,然后再将其展示出来
问题
签名&验证略麻烦,官方文档:https://doc.open.alipay.com/doc2/detail.htm?treeId=200&articleId=105351&docType=1
其中有一个SHA1WithRSA算法(用rsa私钥给数据签名--基于sha1算法),python版本代码如下(需要引用M2Crypto库的EVP类):
print '-'*100, ' ', 'sign before:', sign private_key = """-----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQC/LW6rMzSILfH6reAxdZUdgq/Zo9fyjGnNCXYjGmuzFwEgRNTWAs9x2wK7rrzfTma jiJKlvksvcLFCo37Jdzf8nY79789N2e0MAAIwIjgANFUI4nlkA3x7cQv1LPo1b5izNtIzCDyBqhyy07 xPy2Qu6JQ0i/NZoTHNcZY1p7CZhwIDAQABAoGBAIT9f90Mc+C/xXNS/YCqgR7USKwn9BNAZmFB0bK9s GoW+KuP9lciAVj8t7wD5FObYH8mhI1UAU1xIX5v6cUQcBrQ0Gt9Pg5OBzUxFFruVMASpt6Q1k+YuOhk YnrQvK2Wab7asV2QCZ5Ac8+l7F/HR237d4BQUZ3OrUnN+mF+wfJxAkEA6ts6+VL0qIchJIJjnjw/MRU 7wbHf4IO3AngplHVnAKTKv067X4psEDvxQBM8YUZcN7jAsagGnHsJ2ryGlqXf+wUILNBjhyIEi3JB1o 0UTN2mV+6UaqBukWIBgne/bi9CAV51d7W33h5ULywwYUyGsIr7hZetby9xzKS4bGZG+JvjWuUCQGSAT ltVSYc41FD4T0Luiygo6vp3cNN16gHvg/OYzewzmOOHAJ3g8V99Fz8RPDxwTJQ3xpX/zlx2NoBZPssG zrMCQHhLfA6fIQBsETaPqW+qPshy1LqYGUTCKlaGI00UhUXJ+bjk00wevLx9kS1j8zXHzG6qp6xzvPa 5n5nLDmiu7iECQDZPSqqK78xiwvyGD9UjpBUSnPvht9Zwm0FRO4OKtVtnzgSYylms+WS8KpP41Sx51p +eA5GoNkGnBK9cOyyVsTY= -----END RSA PRIVATE KEY-----""" key = EVP.load_key_string(private_key) key.reset_context(md='sha1') key.sign_init() key.sign_update(sign) sign = base64.b64encode(key.sign_final()) sign = quote(sign) print '-'*100, ' ', 'sign after:', sign