写了一个.py
功能:用户点击获取按钮,后台自动给他发送一条短信(包含随机账号密码).
`#coding:utf-8
import MySQLdb as mdb;
import sys;
import requests;
import json;
#连接数据库
con = mdb.connect('host','user','password','lab');
cur = con.cursor()
cur.execute("SET @id = (SELECT user_id FROM xy_q_ticket_record ORDER BY id DESC LIMIT 1)")
#查询活动表中最后的那条数据
cur.execute("SELECT a.id, a.user_id, b.id, b.phone from xy_q_ticket_record a, xy_member b where a.user_id = b.id and b.id = @id")
#关联查询,获取用户手机号码
last_phone = cur.fetchone()[3]
#定义手机号码
cur.execute("SELECT * from xy_aqiyi ORDER BY rand() limit 0,1")
#在爱奇艺表格中随机获取
all_aqiyi = cur.fetchone()
aqiyi_user = all_aqiyi[1]
#定义账号
aqiyi_password = all_aqiyi[2]
#定义密码
con.close()
#关闭数据库
msg = "您的专属账号为:%s,密码为:%s【name】" % (aqiyi_user,aqiyi_password)
#短信接口
def send_messag_example():
resp = requests.post(("http://sms-api.luosimao.com/v1/send.json"),
auth=("api", "XXXXX"),
data={
"mobile": last_phone,
"message": msg,
},timeout=3 , verify=False);
result = json.loads( resp.content )
print result
if __name__ == "__main__":
send_messag_example();`
OK,这个仅仅是一个Python脚本吧,但是怎么让他去运行呢?不能手动在idle里面点击运行吧。。
我们APP后台是php+mysql,
在你们后台的php里面 用
exec
函数去运行这个脚本如:
exec("/bin/python /xxxx/xxxx/xxx/xxx.py");
前提是你们php.ini里面没有禁用掉这个exec函数