├── README.md ├── alipay.py └── whmcs ├── alipaypersonal.php └── callback ├── alipaypersonal_callback.php └── pay-with-alipay.png /README.md: -------------------------------------------------------------------------------- 1 | #python版的 whmcs 的支付宝免签接口 2 | 3 | ##依赖: 4 | python,pyquery,requests 5 | 使用 pip 进行第三方库的安装 6 | 1、pip install pyquery 7 | 2、pip install requests 8 | 9 | ##使用方法: 10 | 先安装依赖、 11 | whmcs 安装 whmcs 文件夹里面的接口文件。并填写 key 12 | 填写 alipay.py里面的信息: 13 | key;api;接收邮件和发送邮件的邮件,密码。还有 cookies 的ALIPAYJSESSIONID 14 | 15 | 建议使用 screen 进行守护,没有的话也可以。 16 | Python alipay.py跑起来,screen 后台运行就好。 17 | ## 关于ALIPAYJSESSIONID的说明: 18 | 登陆https://lab.alipay.com/consume/record/items.htm 19 | 打开开发者工具(F12)里面的 console,输入 document.cookie 20 | 将ALIPAYJSESSIONID的值尽快复制到 alipay.py里面,并尽快跑起来。 21 | 22 | ##Thank: 23 | whmcs 的接口来自 https://github.com/qibinghua/whmcs_alipaypersonal 24 | 25 | -------------------------------------------------------------------------------- /alipay.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | from pyquery import PyQuery as pq 3 | import requests 4 | import time 5 | import smtplib 6 | from email.mime.text import MIMEText 7 | orderList = {} 8 | SessionID = "" # cookies中的ALIPAYJSESSIONID值 9 | key = " XXXXXX" # API 密匙 10 | api = "XXXXX" # API 地址 11 | mailto_list=['xxx@qq.com','xxxx@qq.com'] #收件人(列表) 12 | mail_host="smtp.qq.com" #使用的邮箱的smtp服务器地址 13 | mail_user="xxx" # 发邮件QQ 帐号 14 | mail_pass="xxxx" # QQ密码 15 | mail_postfix="qq.com" #邮箱的后缀 16 | def send_mail(to_list,sub,content): 17 | me="alipay"+"<"+mail_user+"@"+mail_postfix+">" 18 | msg = MIMEText(content,_subtype='plain') 19 | msg['Subject'] = sub 20 | msg['From'] = me 21 | msg['To'] = ";".join(to_list) #将收件人列表以‘;’分隔 22 | try: 23 | server = smtplib.SMTP() 24 | server.connect(mail_host) #连接服务器 25 | server.login(mail_user,mail_pass) #登录操作 26 | server.sendmail(me, to_list, msg.as_string()) 27 | server.close() 28 | except: 29 | exit() 30 | def postData(PaymentID, Time, Name, Amount): 31 | data = {'key': key,'ddh': PaymentID,'time': Time,'name': Name,'money': Amount} 32 | requests.post(api, data=data,timeout=5) 33 | def check_order(SessionID): 34 | localtime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 35 | print "staring get order", localtime 36 | r = requests.get("https://lab.alipay.com/consume/record/items.htm", cookies = {'ALIPAYJSESSIONID': SessionID},timeout=20) 37 | if r.url.startswith('https://auth.alipay.com/'): 38 | try: 39 | send_mail(mailto_list,"alipay dead","alipay dead") 40 | exit() 41 | except: 42 | exit() 43 | orderTable = pq(r.text)("tbody tr") 44 | for order in orderTable: 45 | order_data = {} 46 | order_pq = pq(order) 47 | try: 48 | order_data['money'] = order_pq(".amount.income").text() # 交易金额 49 | if order_data['money'] == "": 50 | continue 51 | order_data['time'] = order_pq(".time").text() # 交易时间 52 | order_data['name'] = order_pq(".name.emoji-li").text()[:-7].encode("utf-8") # 描述 53 | order_data['ddh'] = order_pq(".number").text() # 交易号 54 | if order_data['ddh'] in orderList: 55 | print "all order already exist" 56 | break 57 | else: 58 | postData(order_data['ddh'],order_data['time'],order_data['name'],order_data['money']) 59 | orderList[order_data['ddh']] = order_data 60 | except Exception as e: 61 | print e 62 | try: 63 | send_mail(mailto_list,"alipay dead","alipay dead") 64 | exit() 65 | except: 66 | exit() 67 | if __name__ == "__main__": 68 | while True: 69 | print len(orderList) 70 | if len(orderList) > 1000: 71 | orderList = {} 72 | check_order(SessionID) 73 | time.sleep(5) -------------------------------------------------------------------------------- /whmcs/alipaypersonal.php: -------------------------------------------------------------------------------- 1 | array( 8 | "Type" => "System", 9 | "Value" => "Alipay 支付宝收款接口" 10 | ), 11 | "seller_email" => array( 12 | "FriendlyName" => "卖家支付宝帐户", 13 | "Type" => "text", 14 | "Size" => "32", 15 | ), 16 | "security_code" => array( 17 | "FriendlyName" => "安全检验码", 18 | "Type" => "text", 19 | "Size" => "32", 20 | ), 21 | ); 22 | 23 | return $configarray; 24 | } 25 | 26 | function alipaypersonal_form($params) { 27 | 28 | # Invoice Variables 29 | $systemurl = $params['systemurl']; 30 | $invoiceid = $params['invoiceid']; 31 | $amount = $params['amount']; # Format: ##.## 32 | $seller_email = $params['seller_email']; 33 | $name = 'whmcs_' . $invoiceid; 34 | $memo = "请勿修改付款说明里内容,否则无法完成订购"; 35 | $form_html = '
'; 42 | $img = $systemurl . "/modules/gateways/callback/pay-with-alipay.png"; //这个图片要先存放好. 43 | $code = $form_html . '