Senaryo :
Sevk edilen siparişleri alıp ilgili cariye mail atar.
Örnekler diadevdays sunucusu üzerinde çalışmaktadır.
Örnek Kod (python):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# -*- coding: utf-8 -*- ''' Örnek çalışma: Sevkedilen siparişleri listele ve mail gönder. ''' import sys import json from pprint import pprint import urllib2 # servis çağrısı atılacak adres ön eki # diadevdays sunucusundaki ilgili firma kodu firma_kodu = 4 # diadevdays sunucusundaki ilgili dönem kodu donem_kodu = 1 def callWs(wsAdres, postBody): # Gönderilen adrese, gönderilen json çağrısı atar, # sonuç başarılıysa döndürür, yoksa çıkar req = urllib2.Request(wsAdres, data = json.dumps(postBody), headers = { "Content-Type" : "application/json" }) wsResult = urllib2.urlopen(req).read() wsResult = json.loads(wsResult) # sonuç kodu 200 döndüyse başarılı if wsResult and wsResult[ 'code' ] = = '200' : # msg içerisinde sessin id çıkaralım return wsResult else : pprint(wsResult) sys.exit( 0 ) ############################################ # 1. AŞAMA : SESSION ID ALALIM # login ws parametreleri postBody = { "login" : { "username" : 'ws' , "password" : 'ws' , "disconnect_same_user" : True , "lang" : 'tr' , "params" : { "apikey" : "773f9085-9dc8-4f50-b34d-f7b56da33b5f" } } } wsResult = callWs(wsAdresMain + 'sis/json' , postBody) session_id = wsResult[ 'msg' ] print "session_id: %s" % session_id ############################################ # 2. AŞAMA : SEVK EDİLEN SİPARİŞLERİ LİSTELEYELİM. postBody = { "scf_siparis_listele" : { "session_id" : session_id, "firma_kodu" : firma_kodu, "donem_kodu" : donem_kodu, "filters" :[{ "field" : "siparisdurum" , "operator" : "=" , "value" : "- Tamamı Sevk Edilmiş" }], "sorts" : [{ "field" : "_cdate" , "sorttype" : "DESC" }], "params" : "", "limit" : 1 , "offset" : 0 } } siparisResult = callWs(wsAdresMain + 'scf/json' , postBody) siparisResult = siparisResult[ 'result' ] ############################################ # 3. AŞAMA : SEVK EDİLEN SİPARİŞLER İÇİN MAIL GÖNDERELİM. for siparis in siparisResult: # Sipariş carisinin e-postasını bulalım. postBody = { "scf_carikart_getir" : { "session_id" : session_id, "firma_kodu" : firma_kodu, "donem_kodu" : donem_kodu, "filters" : "", "sorts" : "", "params" : { "_key" : siparis.get( '_key_scf_carikart' ) or 0 }, "limit" : 1 , "offset" : 0 } } cariResult = callWs(wsAdresMain + 'scf/json' , postBody) cariResult = cariResult[ 'result' ] subject = raw_input ( "Gönderilecek e-postanın konusunu giriniz: " ) body = raw_input ( "Gönderilecek e-postanın içeriğini giriniz: " ) if cariResult[ 'eposta' ]: # Elimizdeki bilgileri kullanarak e-postamızı oluşturup gönderelim. postBody = { "sis_eposta_gonder" : { "session_id" : session_id, "firma_kodu" : firma_kodu, "donem_kodu" : donem_kodu, "sender" : "bilgi@dia.com.tr" , "cc" : cariResult[ 'eposta' ], "bcc" : "", "subject" : subject, "body" : body } } callWs(wsAdresMain + 'sis/json' , postBody) print u "'%s' ünvanlı cariye eposta gönderildi. (Eposta Adresi:%s)" % (cariResult[ 'unvan' ], cariResult[ 'eposta' ]) else : print u "DİKKAT: '%s' ünvanlı cariye eposta adresi tanımlanmamış!" % cariResult[ 'unvan' ] |