You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
208 lines
5.7 KiB
208 lines
5.7 KiB
import utils,time,os,sys |
|
from utils import cfg |
|
|
|
|
|
|
|
|
|
|
|
#获取PID,记录基础信息 |
|
def getPidRecordPose(): |
|
params = { |
|
"photo_group_id":int(time.time()), |
|
"customer_id":cfg("customer.id"), |
|
"platform":cfg("customer.platform"), |
|
} |
|
url = cfg("api.domain")+cfg("api.getPid") |
|
data,status = utils.requestUrl(url,"GET",params) |
|
if status != "success": |
|
return 0,"获取PID失败" |
|
pid = data["pid"] |
|
|
|
#记录基础信息 |
|
params = { |
|
"pid":pid, |
|
"shop_id":cfg("account.shopId"), |
|
"peoples":cfg("customer.peoples"), |
|
"props":cfg("customer.props"), |
|
"pets":cfg("customer.pets"), |
|
"people_pose":cfg("customer.people_pose"), |
|
} |
|
url = cfg("api.domain")+cfg("api.recordPose") |
|
data,status = utils.requestUrl(url,"POST",params) |
|
if status != "success": |
|
return 0,"记录基础信息失败" |
|
print(f"记录基础信息成功,PID:{pid}") |
|
return pid,"success" |
|
|
|
|
|
#获取照片上传的地址, 上传到脸部位置,上传到卡通图片的位置, |
|
def uploadImages(pid,imagePath): |
|
|
|
#检测文件图片是否存在 |
|
if not os.path.exists(imagePath): |
|
return "文件不存在" |
|
|
|
|
|
ossFacePath = f"photos/{pid}/cartoon/origin/face.jpg" |
|
ossPath = f"photos/{pid}/cartoon/cartoon_image/1.png" |
|
utils.oss().put_object_from_file(ossFacePath,imagePath) |
|
utils.oss().put_object_from_file(ossPath,imagePath) |
|
callbackImageUpload(pid) |
|
return "success" |
|
|
|
#下单 |
|
def makeOrder(pid): |
|
if pid == 0: |
|
return "PID不能为0" |
|
|
|
params = { |
|
"pid":pid, |
|
"shop_id":cfg("account.shopId"), |
|
"address":{ |
|
"country_id":350206, |
|
"province_id":350000, |
|
"county_id":"0", |
|
"city_id":350200, |
|
"address":"汇金湖里大厦B栋312", |
|
"receive_address":"汇金湖里大厦B栋312", |
|
"send_model_type": 2, |
|
"memo": "测试", |
|
"customer_name": cfg("customer.name"), |
|
"customer_mobile": cfg("customer.mobile") |
|
}, |
|
"order_params": [ |
|
{ |
|
"id": 0, |
|
"discount_name": "", |
|
"discount_amount": 0, |
|
} |
|
], |
|
"carts_info": [ |
|
{ |
|
"prod_id": 7, |
|
"skus": [ |
|
{ |
|
"quantity": 1, |
|
"attrs": [ |
|
{ |
|
"attr_id": 5, |
|
"attr_val_id": 13, |
|
}, |
|
{ |
|
"attr_id": 1, |
|
"attr_val_id": 1, |
|
} |
|
], |
|
} |
|
] |
|
} |
|
], |
|
"cartoon_pic_no": 1, |
|
"product_name": "badge", |
|
"platform": 99 |
|
} |
|
url = cfg("api.domain")+cfg("api.order") |
|
data,status = utils.requestUrl(url,"POST",params) |
|
print(f"下订单结果:{data}") |
|
|
|
if status != "success": |
|
return 0,"下单失败" |
|
|
|
status = submitModeling(data["order_ids"][0]) |
|
if status != "success": |
|
return 0,"提交建模失败" |
|
return data["order_ids"][0],"success" |
|
|
|
#图片上传回调 |
|
def callbackImageUpload(pid): |
|
params = { |
|
"pid":pid, |
|
"token":utils.getToken(), |
|
} |
|
url = cfg("api.domain")+cfg("api.callbackImageUpload") |
|
data,status = utils.requestUrl(url,"GET",params) |
|
print(f"图片上传回调结果:{data}-{status}") |
|
return "success" |
|
|
|
|
|
#提交建模 |
|
def submitModeling(orderId): |
|
if orderId == 0: |
|
return "订单ID不能为0" |
|
|
|
params = { |
|
"order_id":orderId, |
|
"is_cartoon":1, |
|
} |
|
url = cfg("api.domain")+cfg("api.submitModeling") |
|
data,status = utils.requestUrl(url,"POST",params) |
|
print(f"提交建模结果:{status}") |
|
if status != "success": |
|
return "提交建模失败" |
|
return "success" |
|
|
|
|
|
def imageFolder(): |
|
|
|
#判断目录下是否有images文件夹 和 文件 |
|
if not os.path.exists("images"): |
|
print("images目录不存在") |
|
return |
|
arrFiles = os.listdir("images") |
|
if len(arrFiles) == 0: |
|
print("images目录下没有文件") |
|
return |
|
|
|
#遍历 images 目录下的所有图片 |
|
for image in arrFiles: |
|
#获取完整的图片地址 |
|
imagePath = os.path.join("images",image) |
|
main(imagePath) |
|
|
|
|
|
def main(imagePath = ""): |
|
|
|
#判断文件是否存在 |
|
if not os.path.exists(imagePath): |
|
print(f"图片不存在:{imagePath}") |
|
return None,False |
|
|
|
|
|
print(f"开始处理图片:{imagePath}") |
|
pid,status = getPidRecordPose() |
|
if status != "success": |
|
print(f"获取PID失败:{imagePath}") |
|
return None,False |
|
|
|
status = uploadImages(pid,imagePath) |
|
if status != "success": |
|
print(f"上传图片失败:{imagePath}") |
|
return None,False |
|
|
|
order_id,status = makeOrder(pid) |
|
if status != "success": |
|
print(f"下单失败:{imagePath}") |
|
return None,False |
|
|
|
data = {"pid":pid,"imagePath":imagePath,"orderId":order_id} |
|
print(f"下单成功:{data},移除图片:{imagePath}") |
|
os.remove(imagePath) |
|
return data,True |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
#获取请求参数 |
|
args = sys.argv[1:] |
|
if len(args) == 0: |
|
#需要二次确认是否要处理images目录下的所有图片 |
|
confirmV = input("是否要处理images目录下的所有图片? (y/n)") |
|
if confirmV == "y": |
|
imageFolder() |
|
else: |
|
print("请输入图片路径") |
|
sys.exit(1) |
|
else: |
|
for imagePath in args: |
|
main(imagePath) |
|
print(f"{args}")
|
|
|