mirror of
https://github.com/wahyd4/youxiang.git
synced 2026-08-09 05:16:08 +10:00
Add JD
This commit is contained in:
+82
-23
@@ -1,26 +1,45 @@
|
||||
import pprint
|
||||
'''
|
||||
用suo_mi短址的原因是因为京东使用短址的api需要申请,申请的门槛我放到这里:
|
||||
|
||||
a) 流量稳定且具备一定推广规模的联盟会员,无违规行为,接受业绩考核。
|
||||
|
||||
b) 会员申请标准:开通后两个月内的月订单量>3万单 或 月点击量>30万次
|
||||
|
||||
c) 如开通后2个自然月内如无返回数据,或月订单量达不到要求的,联盟平台将可以关闭高级权限。
|
||||
|
||||
|
||||
就上面第二条是我未来所期待的,所以折中选了个其他短址的
|
||||
'''
|
||||
|
||||
import random
|
||||
import json
|
||||
from untils.jd_api import JdApiClient
|
||||
from untils.suo_im import Suo_mi
|
||||
from untils.common import save_pic, del_pic
|
||||
import itchat
|
||||
|
||||
def jingfen_query():
|
||||
'''
|
||||
def jingfen_query(group_name:str, group_material_id:str, app_key:str, secret_key:str, site_id:str, suo_mi_token:str):
|
||||
''' 方法效率不咋地,不管了
|
||||
https://union.jd.com/openplatform/api/10421
|
||||
:return:
|
||||
'''
|
||||
client = JdApiClient("", "")
|
||||
info = []
|
||||
page_no = str(random.randint(1, 25))
|
||||
page_size = str(random.randint(3, 5)) # 不建议发很多,图片接口会跪
|
||||
|
||||
client = JdApiClient(app_key=app_key, secret_key=secret_key)
|
||||
resp = client.call("jd.union.open.goods.jingfen.query",
|
||||
{"goodsReq":
|
||||
{"sort": "desc",
|
||||
"pageSize": "2",
|
||||
"pageIndex": "1",
|
||||
"eliteId": "31",
|
||||
"sortName": "inOrderCount30DaysSku"
|
||||
"pageSize": page_size,
|
||||
"pageIndex": page_no,
|
||||
"eliteId": group_material_id
|
||||
}})
|
||||
# pprint.pprint(json.loads(resp.json()['jd_union_open_goods_jingfen_query_response']['result']))
|
||||
for data in json.loads(resp.json()['jd_union_open_goods_jingfen_query_response']['result'])['data']:
|
||||
skuName = data['skuName'] ## 商品全名
|
||||
skuId = data['skuId'] ## 商品 sku
|
||||
materialUrl = f'''http://{(data['materialUrl'])}''' ## 商品url
|
||||
sku_name = data['skuName'] ## 商品全名
|
||||
sku_id = data['skuId'] ## 商品 sku
|
||||
material_url = f'''http://{(data['materialUrl'])}''' ## 商品url
|
||||
|
||||
couponInfos = data['couponInfo'] ## 优惠券列表
|
||||
# 查找最优优惠券
|
||||
@@ -30,25 +49,65 @@ def jingfen_query():
|
||||
coupon_link = couponInfo['link'] ## 优惠券领取地址
|
||||
|
||||
price = data['priceInfo']['price'] ## 商品价格
|
||||
lowest_coupon_price = data['priceInfo']['lowestCouponPrice'] ## 商品价格
|
||||
|
||||
print(skuName)
|
||||
print(skuId)
|
||||
print(discount)
|
||||
print(coupon_link)
|
||||
print(price)
|
||||
print(materialUrl)
|
||||
# print(skuName)
|
||||
# print(skuId)
|
||||
# print(discount)
|
||||
# print(coupon_link)
|
||||
# print(price)
|
||||
# print(materialUrl)
|
||||
|
||||
## 获取 images
|
||||
image_list = []
|
||||
images_count = 0
|
||||
for image in data['imageInfo']['imageList']:
|
||||
image_url = image['url']
|
||||
print(image_url)
|
||||
images_count += 1
|
||||
if images_count > 3: ## 3个以上图片就不发了
|
||||
pass
|
||||
else:
|
||||
image_url = image['url']
|
||||
filename = save_pic(image_url, sku_id)
|
||||
groups = itchat.search_chatrooms(name=f'''{group_name}''')
|
||||
for room in groups:
|
||||
room_name = room['UserName']
|
||||
itchat.send('@img@%s' % (f'''{filename}'''), room_name)
|
||||
del_pic(filename)
|
||||
# print(image_url)
|
||||
|
||||
# 得到短址
|
||||
duanzhi = tb_share_text(app_key, secret_key, material_url, coupon_link, site_id, suo_mi_token)
|
||||
# print(duanzhi)
|
||||
share_text = f'''【京东】{sku_name}\n——————————\n 【原价】¥{price}\n 【爆款价】¥{lowest_coupon_price}\n抢购地址:{duanzhi}'''
|
||||
|
||||
print('-----------------------------------')
|
||||
# def share_text():
|
||||
groups = itchat.search_chatrooms(name=f'''{group_name}''')
|
||||
for room in groups:
|
||||
room_name = room['UserName']
|
||||
itchat.send(share_text, room_name)
|
||||
|
||||
def tb_share_text():
|
||||
raise NotImplementedError
|
||||
def tb_share_text(app_key, secret_key, material_url, coupon_url, site_id, suo_mi_token):
|
||||
'''
|
||||
:param material_url: 物料的url
|
||||
:param coupon_url: 优惠券的url
|
||||
:param site_id: 网站id
|
||||
:param suo_mi_token: suo_mi网站的token
|
||||
:return: string ,返回一个suo_mi的短址
|
||||
'''
|
||||
client = JdApiClient(app_key=app_key, secret_key=secret_key)
|
||||
|
||||
resp = client.call("jd.union.open.promotion.common.get",
|
||||
{"promotionCodeReq":
|
||||
{
|
||||
"siteId": site_id,
|
||||
"materialId": material_url,
|
||||
"couponUrl": coupon_url
|
||||
}})
|
||||
x = json.loads(resp.json()['jd_union_open_promotion_common_get_response']['result'])['data']['clickURL']
|
||||
|
||||
# 直接返回短址
|
||||
url = x
|
||||
c = Suo_mi(app_key=suo_mi_token).get_short_url(url)
|
||||
return c
|
||||
|
||||
if __name__ == '__main__':
|
||||
jingfen_query()
|
||||
+46
-41
@@ -12,49 +12,54 @@ def tb_share_text(group_name: str, material_id: str, app_key, app_secret, adzone
|
||||
:param material_id:
|
||||
:return:
|
||||
'''
|
||||
material_id = str(random.choices(material_id.split(','))[0])
|
||||
print(material_id)
|
||||
groups = itchat.search_chatrooms(name=f'''{group_name}''')
|
||||
for room in groups:
|
||||
group_name = room['UserName']
|
||||
time.sleep(random.randint(1, 5))
|
||||
tb_client = TbApiClient(app_key=app_key, secret_key=app_secret, adzone_id=adzone_id)
|
||||
res = tb_client.taobao_tbk_dg_optimus_material(material_id)
|
||||
json_data = json.loads(res)['tbk_dg_optimus_material_response']['result_list']['map_data']
|
||||
count = 0
|
||||
for item in json_data:
|
||||
count += 1
|
||||
if str(item).find("coupon_share_url") > -1:
|
||||
coupon_share_url = "https:" + item['coupon_share_url']
|
||||
coupon_amount = item['coupon_amount']
|
||||
pict_url = "https:" + str(item['pict_url'])
|
||||
title = item['title']
|
||||
item_id = item['item_id']
|
||||
filename = save_pic(pict_url, item_id)
|
||||
zk_final_price = item['zk_final_price']
|
||||
# 发送图片
|
||||
itchat.send('@img@%s' % (f'''{filename}'''), group_name)
|
||||
try:
|
||||
material_id = str(random.choices(material_id.split(','))[0])
|
||||
print(material_id)
|
||||
groups = itchat.search_chatrooms(name=f'''{group_name}''')
|
||||
for room in groups:
|
||||
group_name = room['UserName']
|
||||
time.sleep(random.randint(1, 5))
|
||||
tb_client = TbApiClient(app_key=app_key, secret_key=app_secret, adzone_id=adzone_id)
|
||||
res = tb_client.taobao_tbk_dg_optimus_material(material_id)
|
||||
json_data = json.loads(res)['tbk_dg_optimus_material_response']['result_list']['map_data']
|
||||
count = 0
|
||||
for item in json_data:
|
||||
count += 1
|
||||
if str(item).find("coupon_share_url") > -1:
|
||||
coupon_share_url = "https:" + item['coupon_share_url']
|
||||
coupon_amount = item['coupon_amount']
|
||||
pict_url = "https:" + str(item['pict_url'])
|
||||
title = item['title']
|
||||
item_id = item['item_id']
|
||||
filename = save_pic(pict_url, item_id)
|
||||
zk_final_price = item['zk_final_price']
|
||||
# 发送图片
|
||||
itchat.send('@img@%s' % (f'''{filename}'''), group_name)
|
||||
|
||||
itchat.send(f''' {title} \n【在售价】¥{zk_final_price}\n【券后价】¥{round(float(zk_final_price) - float(coupon_amount),
|
||||
2)}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
|
||||
title, coupon_share_url)}),去【tao寶】下单\n''', group_name)
|
||||
itchat.send(f''' {title} \n【在售价】¥{zk_final_price}\n【券后价】¥{round(float(zk_final_price) - float(coupon_amount),
|
||||
2)}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
|
||||
title, coupon_share_url)}),去【tao寶】下单\n''', group_name)
|
||||
|
||||
time.sleep(2)
|
||||
del_pic(filename)
|
||||
else:
|
||||
click_url = "https:" + item['click_url']
|
||||
title = item['title']
|
||||
item_id = item['item_id']
|
||||
pict_url = "https:" + str(item['pict_url'])
|
||||
zk_final_price = item['zk_final_price']
|
||||
print(pict_url)
|
||||
filename = save_pic(pict_url, item_id)
|
||||
itchat.send('@img@%s' % (f'''{filename}'''), group_name)
|
||||
itchat.send(
|
||||
f'''{title} \n【在售价】¥{zk_final_price}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
|
||||
title, click_url)}),去【tao寶】下单\n''', group_name)
|
||||
time.sleep(2)
|
||||
del_pic(filename)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
tb_share_text(group_name, material_id, app_key, app_secret, adzone_id)
|
||||
|
||||
time.sleep(2)
|
||||
del_pic(filename)
|
||||
else:
|
||||
click_url = "https:" + item['click_url']
|
||||
title = item['title']
|
||||
item_id = item['item_id']
|
||||
pict_url = "https:" + str(item['pict_url'])
|
||||
zk_final_price = item['zk_final_price']
|
||||
print(pict_url)
|
||||
filename = save_pic(pict_url, item_id)
|
||||
itchat.send('@img@%s' % (f'''{filename}'''), group_name)
|
||||
itchat.send(
|
||||
f'''{title} \n【在售价】¥{zk_final_price}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
|
||||
title, click_url)}),去【tao寶】下单\n''', group_name)
|
||||
time.sleep(2)
|
||||
del_pic(filename)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'''tb function''')
|
||||
Reference in New Issue
Block a user